我有問題,根據搜索表單顯示「訪問」表的結果!空的結果在哪裏條款
這是代碼!
<?php
$date1 = $_POST['day'] . "-" . $_POST['month'] . "-" . $_POST['year'];
$date2 = $_POST['day1'] . "-" . $_POST['month1'] . "-" . $_POST['year1'];
$product=$_POST['product'];
$region=$_POST['region'];
$speciality=$_POST['speciality'];
$type=$_POST['visit_type'];
$query="SELECT id, name, seller_1_name, seller_2_name FROM visits Where (speciality ='$speciality') AND (type ='$type') AND (product ='$product') AND (date BETWEEN '$date1' AND '$date2')";
$num=mysql_numrows($result);
$row = mysql_fetch_array($result);
?>
<h3> Showing results where Product is <?php echo $product; ?>, Speciality is <?php echo $speciality ?>, Region is <?php echo $region ?> and Type is <?php echo $type ?>.</h3>
<table class="auto-style4" style="width: 100%" border="1"><tr>
<td style="height: 18px">ID</td>
<td style="height: 18px">Name</td>
<td style="height: 18px">seller one name</td>
<td style="height: 18px">seller 2 name</td>
</tr>
<tr>
<?php
$i=0;
while ($i < $num) {
$f1=mysql_result($result,$i,"id");
$f2=mysql_result($result,$i,"name");
$f4=mysql_result($result,$i,"seller_1_name");
$f5=mysql_result($result,$i,"seller_2_name");
?>
<td><?php echo $f1; ?> </td>
<td><?php echo $f2; ?> </td>
<td><?php echo $f4; ?></td>
<td><?php echo $f5; ?></td>
</tr>
<?php
$i++;
}
?>
它顯示與輸入了正確的變量的標題,但表是空的,錯誤代碼:
警告:mysql_numrows():提供的參數不是在/ home/ebarea一個有效的MySQL結果資源/ public_html /.../.../ results_submitt.php 175行
警告:mysql_fetch_array():提供的參數不是在/ home/ebarea/public_html/.../...中的有效MySQL結果資源/results_submitt.php在線176
什麼是錯誤>!
在'mysql_query()'調用後面添加'或者死(mysql_error())'來查看實際的數據庫錯誤。但我的猜測是,你的日期需要'yyyy-mm-dd'格式。 – ThiefMaster
你似乎沒有真正查詢數據庫? $結果從哪裏來? –
**您的代碼容易受到SQL注入的攻擊**您應該使用準備好的語句,將您的變量作爲參數傳遞給其中,而這些參數不會針對SQL進行評估。如果你不知道我在說什麼,或者如何解決它,請閱讀[Bobby Tables](http://bobby-tables.com)的故事。你也似乎永遠不會*運行*你的查詢... – eggyal