我写了一个从购物车中删除商品的功能;成功消息闪烁,但该项目未被删除。控制台中没有标记错误消息。但是我觉得我的查询错了。
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.';
答案 0 :(得分:0)
你能试试吗?
我认为你需要追加价值。
$sql = "DELETE FROM cart WHERE id =".$cart_item_id;
答案 1 :(得分:0)
请更新以下代码并尝试:
$sql = "DELETE FROM cart WHERE id =" . $cart_item_id; // update this
$db->query($sql); //add this new line in code.
如果有任何困惑请让我问。 感谢...