PHP更新购物车数量(表单部分/PHP处理部分)

时间:2021-05-26

表单部分
复制代码 代码如下:
<form action="?action=edit_num" method="post" name="car<?php $c_rs['id'];?>" id="car<?php $c_rs['id'];?>">
<input name="suliang[<?php echo $c_rs['sp_id'];?>]" type="text" id="suliang[<?php echo $c_rs['sp_id'];?>]" value="<?php echo $c_rs['suliang'];?>"/>
<input type="submit" name="button" id="button" value="更新购物车" />
</form>

PHP 处理部分
复制代码 代码如下:
<?php
require 'config.inc.php';
require 'checklogin.php';
$username = $_SESSION['username'];
$action = $_GET['action'];
switch ($action) {
case "edit_num":

$arr = $arr = $_POST['suliang'];
foreach($arr as $key=>$value){
$sqlgx = "update `cartemp` set suliang='$value' where username='".$username."' and flag=0 and sp_id='".$key."'";
mysql_query($sqlgx, $conn);
echo "<script>location.href='shopcat.php'</script>";
}
break;

case "null":
$null_sql = "delete from `cartemp` where username='$username' and flag=0 ";
mysql_query($null_sql, $conn);
echo "<script>location.href='shopcat.php'</script>";
break;
case "del":
$id = $_GET['id'];
$del_sql = "delete from `cartemp` where id=$id";
mysql_query($del_sql, $conn);
echo "<script>location.href='shopcat.php'</script>";
break;
}
?>

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章