第七十四天休息 PHP登入控制,主界面显示,添加购物车和下单
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第七十四天休息 PHP登入控制,主界面显示,添加购物车和下单相关的知识,希望对你有一定的参考价值。
登陆界面 index.php
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>优先显示界面</title> <link rel="shortcut icon" type="image/x-icon" href="my-img/title.ico"/> <form action="intest.php" method="post"> <div>用户名:<input type="text" name="uid" /></div> <div>密码:<input type="text" name="word" /></div> <div><input type="submit" value="提交" /></div> </form>
主界面(水果店)index-fruit.php
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>优先显示界面</title> <link rel="shortcut icon" type="image/x-icon" href="my-img/title.ico"/> <h1 align="center">水果店</h1> <table align="center" width="1000px" border=‘1px‘> <tr align="center"> <td>水果名称</td> <td>水果价格</td> <td>水果产地</td> <td>水果库存</td> <td>*</td> </tr> <?php session_start(); if(!isset($_SESSION[‘uid‘])) { header(‘location:index.php‘); } include "class/uniondatabase-class.php"; $db=new unionDatabase(); $sql="select * from fruit"; $result=$db->query($sql); foreach($result as $i) { echo"<tr align=‘center‘> <td>$i[1]</td> <td>$i[2]</td> <td>$i[3]</td> <td>$i[4]</td> <td> <a href=‘intest-shoppingcart.php?code={$i[0]}‘> 加入购物车 </a> </td> </tr>"; } ?> </table><br> <div> <a href="index-shoppingcart.php" target="_blank"> 查看购物车 </a> </div> <style type="text/css"> table { border-color:#0F0; } a { text-decoration:none; color:#00F; } a:hover { color:#F00; } div { position:absolute; left:75%; font-weight:bold; font-size:16px; } </style>
购物车界面 index-shoppingcart.php
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>购物车</title> <h1 align="center">购物车明细</h1> <table width="1000px" border="1px" align="center" bordercolor="#00FF00"> <tr align=‘center‘> <td>水果名称</td> <td>水果价格</td> <td>挑选数量</td> <td>*</td> </tr> <?php session_start(); if(!isset($_SESSION[‘uid‘])) { header(‘location:index.php‘); } else if(isset($_SESSION[‘FruitName‘])) { include "class/uniondatabase-class.php"; $db=new unionDatabase(); $attr=$_SESSION[‘FruitName‘]; foreach($attr as $i) { $sql="select * from fruit where Ids=‘{$i[0]}‘"; $result=$db->query($sql); echo "<tr align=‘center‘> <td>{$result[0][1]}</td> <td>{$result[0][2]}</td> <td>{$i[1]}</td> <td> <a href=‘intest-deletefruit.php?code=$i[0]‘> 删除数量 </a> </td> </tr>"; } } ?> </table><br /> <div><a href=‘intest-upfruit.php‘>提交订单</a></div> <style type="text/css"> table { border-color:#0F0; } a { text-decoration:none; color:#00F; } a:hover { color:#F00; } div { position:absolute; left:80%; font-weight:bold; font-size:16px; } </style>
登入处理界面
<?php session_start(); include "class/uniondatabase-class.php"; $db=new unionDatabase(); $uid=$_POST[‘uid‘]; $word=$_POST[‘word‘]; $sql="select count(*) from user where Uid=‘$uid‘ and PassWord=‘$word‘"; $result=$db->queryStr($sql); if($result==1) { $_SESSION[‘uid‘]=$uid; header("location:index-fruit.php"); } else { header(‘location:index.php‘); }
商品加入购物车处理界面 intest-shoppingcart.php
<?php session_start(); $code=$_GET[‘code‘]; //第一次点击 if(!isset($_SESSION[‘FruitName‘])) { $attr=array(array($code,1)); //存放商品和个数的数组 $_SESSION[‘FruitName‘]=$attr; } //第多次点击 else { $attr=$_SESSION[‘FruitName‘]; if(FruitIsset($code)) { foreach($attr as $k=>$i) { if($i[0]==$code) { $attr[$k][1]=$i[1]+1; } } $_SESSION[‘FruitName‘]=$attr; } else { $arr=array($code,1); array_push($attr,$arr); $_SESSION[‘FruitName‘]=$attr; } } header(‘location:index-fruit.php‘); //判断购物车是否存在某种水果的方法 function FruitIsset($code) { $attr=$_SESSION[‘FruitName‘]; $t=false; foreach($attr as $i) { $t=$t || in_array($code,$i); } return $t; }
购物车商品删除处理界面 intest-deletefruit.php
<?php session_start(); $code=$_GET[‘code‘]; $attr=$_SESSION[‘FruitName‘]; foreach($attr as $k=>$i) { if($i[0]==$code) { $attr[$k][1]=$i[1]-1; if($attr[$k][1]==0) { array_splice($attr,$k,1); } } $_SESSION[‘FruitName‘]=$attr; } header(‘location:index-shoppingcart.php‘);
下单处理界面 intest-upfruit.php
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <?php session_start(); $Fruit=$_SESSION[‘FruitName‘]; $Uid=$_SESSION[‘uid‘]; include "class/uniondatabase-class.php"; $db=new unionDatabase(); $sql1="select UserName from user where Uid=‘$Uid‘"; $UserName=$db->queryStr($sql1); //获取用户名 $Time=date("Y-m-d H:i:s",time()); //获取下单时间 echo $Uid; echo $UserName; echo $Time; $sql2="insert into order values(‘‘,‘$Uid‘,‘$UserName‘,‘$Time‘)"; $db->query($sql2); foreach($Fruit as $i) { $sql3="insert into orderdetails values(‘‘,‘$Uid‘,‘$i[0]‘,‘$i[1]‘)"; $db->query($sql3); }
以上是关于第七十四天休息 PHP登入控制,主界面显示,添加购物车和下单的主要内容,如果未能解决你的问题,请参考以下文章