我遇到了下面的問題,每當我點擊一個項目時,它會捕獲mySQL表上的項目和更新,它只顯示1個項目(我如何讓它顯示所有我檢查過的物品?)。PHP更新MySQL數據庫問題
另外,當我把數量在它不更新mySQL表,它只是說,當我已經把多個數量的每個項目0。
如果沒關係,你們能幫忙嗎?
<tr>
<th>Shirts</th>
<th>Quantity</th>
</tr>
<tr>
<td>
<br />
<input type="checkbox" name="items" value="SH01" /><label for="rd1">Obey T-Shirt: $9.99</label></div> <br />
<input type="checkbox" name="items" value="SH02" /><label for="rd1">Obey Professor: $9.99</label></div> <br />
<input type="checkbox" name="items" value="SH03" /><label for="rd1">Hustle T-Shirt: $9.99</label></div> <br />
<input type="checkbox" name="items" value="SH04" /><label for="rd1">Hip-Hop Support: $9.99</label></div> <br />
<input type="checkbox" name="items" value="SH05" /><label for="rd1">90's Shirt: $9.99</label></div> <br />
<input type="checkbox" name="items" value="SH06" /><label for="rd1">DOPE Shirt: $9.99</label></div> <br />
<br />
</td>
<td>
<br />
<input type="text" name="qty" size ="2"/><br/>
<input type="text" name="qty" size="2"/><br/>
<input type="text" name="qty" size="2"/><br/>
<input type="text" name="qty" size="2"/><br/>
<input type="text" name="qty" size="2"/><br/>
<input type="text" name="qty" size="2"/><br/>
<br />
</td>
</tr>
<tr>
<td>
<br />
<input type="checkbox" name="items" value="SO1" /><label for="rd1">Shoe - Red Lace: $19.99</label></div><br />
<input type="checkbox" name="items" value="SO2" /><label for="rd1">Shoe - Red High Top: $19.99</label></div><br />
<input type="checkbox" name="items" value="SO3" /><label for="rd1">Shoe - White: $19.99</label></div><br />
<input type="checkbox" name="items" value="SO4" /><label for="rd1">Shoe - Black: $19.99</label></div><br />
<input type="checkbox" name="items" value="SO5" /><label for="rd1">Shoe - Black High Top: $19.99</label></div><br />
<input type="checkbox" name="items" value="SO6" /> <label for="rd1">Red Basketball: $19.99</label></div><br />
<br />
</td>
<td>
<br />
<input type="text" name="qty[]" size ="2"/><br/>
<input type="text" name="qty[]" size="2"/><br/>
<input type="text" name="qty[]" size="2"/><br/>
<input type="text" name="qty[]" size="2"/><br/>
<input type="text" name="qty[]" size="2"/><br/>
<input type="text" name="qty[]" size="2"/><br/>
<br />
</td>
</tr>
<tr>
<td>
<br />
<input type="checkbox" name="items" value="SN1" /> <label for="rd1">Snapback Bullets: $29.99</label></div><br />
<input type="checkbox" name="items" value="SN2" /><label for="rd1">Snapback: $29.99</label></div><br />
<input type="checkbox" name="items" value="SN3" /><label for="rd1">Snapback Bullets: $29.99</label></div><br />
<input type="checkbox" name="items" value="SN4" /><label for="rd1">Snapback Bullets: $29.99</label></div><br />
<input type="checkbox" name="items" value="SN5" /><label for="rd1">Snapback Bullets: $29.99</label></div><br />
<input type="checkbox" name="items" value="SN6" /><label for="rd1">Snapback Bullets: $29.99</label></div><br />
<br />
</td>
<td>
<br />
<input type="text" name="qty" size ="2"/><br/>
<input type="text" name="qty" size="2"/><br/>
<input type="text" name="qty" size="2"/><br/>
<input type="text" name="qty" size="2"/><br/>
<input type="text" name="qty" size="2"/><br/>
<input type="text" name="qty" size="2"/><br/>
<br />
</td>
</tr>
</tr>
</table>
<br />
<input type="submit" name="submit">
</form>
<?php
if (isset($_POST['submit']))
{
$con = mysql_connect('$localhost','$url','$pass');
if (!$con)
{
die("Could Not Connect: " . mysql_error());
}
mysql_select_db("$username",$con);
$sql = "INSERT INTO Order_Information(Order_ID,Order_Items,Order_Quantity) VALUES (null,'$_POST[items]','$_POST[qty]')";
mysql_query($sql,$con);
mysql_close($con);
}
?>
執行查詢後得到的錯誤是什麼? –
你可以看看我的網站: http://zim.cs.uow.edu.au/~ga420/order.php 訂單的工作原理,但是當更新訂單的數量時, t更新 – user1618490
複選框值是開啓或沒有。首先你需要命名你的「文本」框來匹配項目名稱,否則將無法引用哪個複選框屬於哪個數量。那麼也可以使用VALUE命名您的複選框作爲名稱 – DevZer0