Ajax + PHP session制作购物车(2)

<?php session_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title><br /> <style type="text/css"> .list{ width:100%; height:30px; margin-top:10px; text-align:center; line-height:30px; vertical-align:middle} </style> <script src=""></script> </head> <body> <div> <h1>大苹果商城</h1> <a href="https://www.jb51.net/zhuxiao.php">注销</a> </div> <br /> <div> <div> <a href="https://www.jb51.net/main.php"><div>浏览商品</div></a> <a href="https://www.jb51.net/zhanghu.php"><div>查看账户</div></a> <a href="https://www.jb51.net/gouwuche.php"><div>查看购物车</div></a> </div> <div> <table cellpadding="0" cellspacing="0"> <tr> <td>商品名称</td> <td>商品单价</td> <td>购买数量</td> <td>操作</td> </tr> <?php include("../DBDA.class.php"); $db = new DBDA(); $attr=array(); if(!empty($_SESSION["gwc"])) { $attr = $_SESSION["gwc"]; } foreach($attr as $k=>$v) { $sql = "select name,price from fruit where ids='{$v[0]}'"; $ashuiguo = $db->Query($sql); echo "<tr><td>{$ashuiguo[0][0]}</td><td>{$ashuiguo[0][1]}</td><td>{$v[1]}</td><td><a href='shanchu.php?sy={$k}'>删除</a></td></tr>"; } ?> </table> <div>提交订单</div><div></div> </div> </div> <script type="text/javascript"> $("#tj").click(function(){ $.ajax({ url:"dingdan.php", dataType:"TEXT", success: function(data){ if(data.trim()=="OK") { alert("购买成功"); } else if(data.trim()=="YEBUZU") { $("#ts").html("余额不足"); $("#ts").css("color","red"); } else { $("#ts").html(data); $("#ts").css("color","red"); } } }); }) </script> </body> </html>

7.购物车页面删除处理页面shanchu.php

<?php session_start(); $sy = $_GET["sy"]; $attr = $_SESSION["gwc"]; if($attr[$sy][1]>1) { $attr[$sy][1] = $attr[$sy][1]-1; } else { unset($attr[$sy]); $attr = array_values($attr); } $_SESSION["gwc"]=$attr; header("location:gouwuche.php"); 8.账户余额页面zhanghu.php <?php session_start(); $uid = $_SESSION['uid']; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title><br /> <style type="text/css"> .list{ width:100%; height:30px; margin-top:10px; text-align:center; line-height:30px; vertical-align:middle} </style> </head> <body> <div> <h1>大苹果商城</h1> <a href="https://www.jb51.net/zhuxiao.php">注销</a> </div> <br /> <div> <div> <a href="https://www.jb51.net/main.php"><div>浏览商品</div></a> <a href="https://www.jb51.net/zhanghu.php"><div>查看账户</div></a> <a href="https://www.jb51.net/gouwuche.php"><div>查看购物车</div></a> </div> <div> <?php include("../DBDA.class.php"); $db = new DBDA(); $sql = "select Account from login where UserName='{$uid}'"; $result = $db->strQuery($sql); echo ("您的账户中还剩余".$result); ?> </div> </div> </body> </html>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjsdfx.html