Maison >développement back-end >tutoriel php >PHP购物车用法之更新购物车数量_PHP教程
购物车数量意思就是在我们买东西时可以随时删除工增加商品,这样我们的购物车就必须更新记录啊,下面我来给大家介绍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; } ?> |
上面全部使用了数据库来操作,下面来个完全的类
代码如下 | 复制代码 |
|