6.再做删除的处理页面goodsdel.php
<?php session_start(); $zj = $_GET["zj"]; //如果该水果数量大于1,减1 //如果该水果数量等于1 移除 $arr = $_SESSION["gwd"]; if($arr[$zj][1]>1){ $arr[$zj][1]=$arr[$zj][1]-1; }else{ unset($arr[$zj]); //清除数组 $arr=array_values($arr); //重新索引数组 } $_SESSION["gwd"] = $arr; header("location:add_list.php");
7..然后做提交页面 :tijiao.php
<?php session_start(); $ids = $_GET["ids"]; //查看余额 $uid = $_SESSION["uid"]; require_once "./DBDA.class.php"; $db = new DBDA(); $sql = "select account from login where username='{$uid}'"; $arr = $db->query($sql,0); $aye = $arr[0][0];//余额 //var_dump($aye); if(!empty($_SESSION["gwd"])){ $arr = $_SESSION["gwd"]; $sum = 0; //$numbers = count($arr); foreach($arr as $v){ $sql = "select * from fruit where ids='{$v[0]}'"; $price = $db->query($sql,0); $dj = $price[0][2]; $sum = $sum+$dj*$v[1]; } }else{ echo "您还未购买商品!"; //header("shopping_list.php"); exit; } //判断余额是否满足购买 if($aye>=$sum){ //判断库存 foreach($arr as $v){ $skc = "select name,numbers from fruit where ids='{$v[0]}'"; $akc = $db->query($sql,0); var_dump($akc); $kc = $akc[0][4];//库存 //var_dump($kc); if($kc<$v[1]){ echo "库存不足!"; exit; } } //提交订单 //账户扣除余额 $skye = "update login set account=account-{$sum} where username='{$uid}'"; $zhye = $db->query($skye); //扣除库存 foreach($arr as $v){ $skckc = "update fruit set numbers=numbers-{$v[1]} where ids='{$v[0]}'"; $sykc = $db->query($skckc); } //添加订单 $ddh = date("Y-m-d H:i:s"); $time = time(); $stjd = "insert into orders values('{$time}','{$uid}','{$ddh}')"; $wcdh = $db->query($stjd); //添加订单详情 foreach($arr as $v){ $ddxq = "insert into orderdetails values('','{$ddh}','{$v[0]}','{$v[1]}')"; $axq = $db->query($ddxq); } }else{ echo "余额不足,请充值!"; exit; } header("location:shopping_list.php");
用户账户余额已经减少:
以上这篇PHP实现一个多功能购物网站的案例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。