아래는 MYSQL 데이터베이스에서 날짜 범위를 검색하는 코드입니다. 날짜를 검색 할 수 있는데 테이블 표제 (Product Desc, New 또는 Own and Date)가 표시되지만 데이터베이스의 결과가 표시되지 않습니까?PHP가 MYSQL 타임 스탬프에서 결과를 표시하지 않음 검색
선택한 날짜 범위의 결과를 표시하기 위해 내 코드를 수정해야하는 방법에 대한 아이디어가 있습니까?
<?php
if(!isset($_POST['find']))
{
?>
<form method = "post" action = "<?php echo $_SERVER['PHP_SELF'];?>">
<table width = "450" align = "center">
<tr>
<td><b><i>Please enter date in the field below (i.e. 11-09-2012)</i></b></td>
</tr>
<tr>
<td>
From :
<input type = "text" name = "small">
To :
<input type = "text" name = "large"></td>
</tr>
<tr>
<td align = "center">
<input type = "submit" name = "find" value = "SEARCH">
<input type = "reset" value = "CLEAR FORM">
</td>
</tr>
</table>
</form>
<?php
}
else
{
$small = trim($_POST['small']);
$large = trim($_POST['large']);
$connection = mysql_pconnect("localhost", "user_name", "password") or die("Connection failed. ".myslq_error());
mysql_select_db("stock") or die("Unable to select db. ".mysql_error());
//Add 1 to the upper range, $large, else it won't make it inclusive
$query = "SELECT * FROM main_stock WHERE curr_timestamp BETWEEN DATE_FORMAT(curr_timestamp,'%".$small."') AND DATE_FORMAT(curr_timestamp, '%".($large+1)."') ORDER BY curr_timestamp";
$result = mysql_query($query) or die(mysql_error());
echo "<table width = '500' align = 'center'>";
echo "<tr><b>";
echo "<td>Product Description</td>";
echo "<td>New or Own?</td>";
echo "<td>Date</td>";
echo "</b></tr>";
while($record = mysql_fetch_object($result))
{
echo "<tr>";
echo "<td>".$record->product_desc."</td>";
echo "<td>".$record->newown."</td>";
$year_part_of_date = explode('-', $record->curr_timestamp);
echo "<td>".$year_part_of_date[0]."</td>";
//if you want the full date replace the $year_part_of_date[0] with $record->date
echo "</tr>";
}
echo "</table>";
}
?>
이 쿼리는 작품을 생성하고 있음을 확인 했, 당신은 다시 결과를 얻고 있다고? – andrewsi
데이터베이스에서 직접 쿼리를 실행하면 어떻게됩니까? $ small과 $ large 값을 사용하여 날짜 문자열의 형식을 지정하는 것은 말이되지 않습니다. –
사용자가 감염된 변수를 이스케이프 처리하지 않았으므로이 스크립트에 SQL 삽입 취약점이있을 수 있습니다. – halfer