我寫了一個函數從購物車中刪除一個項目;成功消息閃爍,但該項目未被刪除。控制檯中沒有標記錯誤消息。不過,我認爲我的查詢是錯誤的。jQuery onclick從mysql表中刪除行
cart.php
<form id='updateCartForm' action="update_cart.php" method="get">
<input name="cart_item_id" type = "hidden" id ="cart_item_id" value='<?=$product['id'];?>'>
</form>
<button class="btn btn-warning" onclick='update_cart(); return false;'>×</button>
footer.php
function update_cart(){
jQuery('#updateCartErrors').html("");
var cart_item_id = jQuery('#cart_item_id').val();
var error = ' ';
var data = jQuery('#updateCartForm').serialize();
jQuery.ajax({
url : '/ecommerce/customer/parsers/update_cart.php ',
method: 'get',
data : data,
success : function(){
location.reload();
},
error : function(){alert("Something went wrong");}
});
}
update_cart.php
<?php
ob_start();
require_once $_SERVER['DOCUMENT_ROOT'].'/ecommerce/core/init.php';
$cart_item_id = $_GET['cart_item_id'];
$sql = "DELETE FROM cart WHERE id = $cart_item_id" ;
//flash success message
$domain =($_SERVER['HTTP_HOST'] != 'localhost')?'.'.$_SERVER['HTTP_HOST']:false;
$_SESSION['success_flash'] = $product['prod_name']. ' was deleted from your cart.';
@ e4c5:是'$ product ['id']'由另一個查詢生成以顯示購物車中的產品。 – Chad
您是否檢查該表單是否正確呈現,但是檢查了html – e4c5
這些'