作者godispower (omg)
看板PHP
標題[請益] php 撈資料庫的問題
時間Thu Jan 28 11:11:43 2010
小弟想請問一個效果如何做
資料庫有四個欄位 id item barcode datearrivetom
我現有兩頁 一頁叫做 whquery.html 一頁叫whquery.php
whquery.html 可以輸入 id, item, barcode...等的資訊
並透過whquery.php 去資料庫把資料抓出來秀在頁面上
我要的效果是 使用者輸入資訊超過三個以上.例如以下
id: 3
item : 33444
barcode: 56789
datearrivetom: 空白
如此輸入時,頁面上會秀出一筆三個資訊都符合的資料
我寫的code:
whquery.html
<form method="post" action="whquery.php">
id : <input name="id" type="text" /><br />
item: <input name="item" type="text" /><br />
barcode: <input name="barcode" type="text" /><br />
datearrivetom: <input name="datearrivetom" type="text" /><br />
<input name="Button1" type="submit" value="query" />
</form>
whquery.php
<?php
$conn = mysql_connect('localhost','root','680712');
mysql_select_db("purchaseinfo",$conn);
$sql = "select * from incoming where id='$_POST[id]' and item='$_POST[item]'";
$result = mysql_query($sql,$conn);
while($row = mysql_fetch_array($result))
{
?>
<tr>
<td align="left" height="20"><?php echo $row["id"]?></td>
<td align="left"><?php echo $row["item"]?></td>
<td align="left"><?php echo $row["barcode"]?></td>
<td align="left"><?php echo $row["datearrivetom"]?></td>
</tr>
<?php
}
mysql_free_result($result);
mysql_close($conn);
?>
問題:
當我在 whquery.html 輸入如下
id: 3
item : 33444
barcode: 空白
datearrivetom: 空白
這樣可以成功 但是如果輸入
id: 3
item : 33444
barcode: 56789 多查一個
datearrivetom: 空白
就會失敗 請問我sql那裡要怎麼改?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 189.250.59.67
推 misssomeone:你輸入三個,可是你的where只有兩個 01/28 11:17
→ godispower:我就是不知道第三個要怎麼加..因為試不出來才請益 01/28 11:37