用戶應該可以刪除特定的行,但程序會繼續刪除第一行。我找到了答案here試過它沒有工作。我不知道我做錯了什麼。Mysql不斷刪除錯誤的表格行
cart.php
<form id='updateCartForm' action="update_cart.php" method="get">
<input name="cart_item_name" type = "hidden" id ="cart_item_name" value='<?=$product['prod_name'];?>'>
<input name="cart_item_id" type = "hidden" id ="cart_item_id" value='<?=$product['id'];?>'>
</form>
update_cart.php
<?php
require_once "core/db.php"
//get data from form
$cart_item_name = $_GET['cart_item_name'];
$cart_item_id = $_GET['cart_item_id'];
//execute query
$sql = "DELETE FROM cart WHERE id =" .$cart_item_id;
$db->query($sql);
//flash success message
$domain =($_SERVER['HTTP_HOST'] != 'localhost')?'.'.$_SERVER['HTTP_HOST']:false;
$_SESSION['success_flash'] = $cart_item_name. ' was deleted from your cart.';
檢查您在'$ cart_item_id'獲得的價值。假設有人發送'cart_item_id'爲'1; DROP TABLE cart;'讀一下[SQL Injection](http://php.net/manual/en/security.database.sql-injection.php) – bansi
@bansi他'只需發送'id'值,整個表就會被清除,因此'id = id'總是成立的。 –