PHP购物网站

news/2024/5/10 5:44:50/文章来源:https://blog.csdn.net/weixin_30695195/article/details/99261376

我使用的phpsteam经常用着用着就闪退,所以做起来挺麻烦的。里面的代码有抄袭借鉴网上的代码,就是那个php做购物网站点击量最高的那个。

但是我很多代码也是自己写的不和其相同。

PHP是一门选修课,大学生上课大家都懂,代码有些方面不规范请见谅。

个人分析与总结:用户充值页面做的不完善,应该用户提交充值然后由管理员收到通知后同意后才能充值成功,没有管理员的管理系统模块,缺少管理员添加用户和添加商品的页面和具体实现。

源码我会在今晚做一些我自知不足的地方后以百度网盘的形式放到这篇博客上。

我已经把管理员用户的管理页面完成了,但是充值模块依旧没做,考试太多。

百度网盘:可扫码

 

 

链接:https://pan.baidu.com/s/1FDul18i6F00V-iDGeZNjew
提取码:epyc

 

与数据库连接的php文件:

conn.php:

<?php
$conn = mysqli_connect("localhost", "root", "123456", "shop") or die("连接数据库服务器失败!".mysqli_error()); //连接MySQL服务器,选择数据库
?>

  

登录页面:当登录admin  账号时到管理员页面

login.php:

<?php
/*** Created by PhpStorm.* User: dada* Date: 2019/6/3* Time: 21:15*/
?>
<!doctype html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport"content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>登录</title>
</head>
<body>
<form action="logincl.php" method="post"><table border="1" align="center"><h1 align="center">登录</h1><tr><td>账号:</td><td><input type="text" name="name"id="name"></td></tr><tr><td>密码:</td><td><input type="password" name="password" id="password"></td></tr><tr><td></td><td align="center"><input type="submit" value="提交" align="center"><input type="reset" value="重置"></td></tr></table>
</form>
</body>
</html>

登录处理:

logincl.php:

<?php
/**
* Created by PhpStorm.
* User: dada
* Date: 2019/6/3
* Time: 21:18
*/

session_start();

include_once("conn.php");
if (!($_POST['name'] and $_POST['password'] )){
echo "<script>alert('输入不允许为空');history.go(-1);</script>";
}else
{
if($_POST['name']=='admin'and $_POST['password']=='123456' )
{
echo "<script>alert('登录成功');location='guanli/adminmian.php';</script>";
}
else {
$sql = "select password,account from login WHERE username = '{$_POST['name']}'";

$result = mysqli_query($conn, $sql);
if ($result) {

$a = mysqli_fetch_object($result);
$account = $a->account;
$password = $a->password;
if ($_POST['password'] == $password) {
$_SESSION["name"] = $_POST['name'];
$_SESSION["account"] = $account;
echo "<script>alert('登录成功');location='main.php';</script>";
} else {
echo "<script>alert('密码错误'+$account);history.go(-1);</script>";
}
} else {
echo "<script>alert('无此账号');history.go(-1);</script>";

}
}
}
?>

主页面:

mian.php:

<?php
/*** Created by PhpStorm.* User: dada* Date: 2019/6/3* Time: 21:20*/?>
<!doctype html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport"content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>购物选择</title><script>function add(){if(!window.confirm('是否要加入购物车??'))return false;}</script>
</head>
<body>
<?php
session_start();
$account=$_SESSION["account"];
echo"<h1 align='center'>".'您的当前余额:'.$account."</h1>"?>
<table align="center" border="1"><tr><td colspan="5" bgcolor="#a9a9a9" align="center">购物信息表</td></tr><tr><td>名称</td><td>价格</td><td>产地</td><td>库存</td><td>操作</td></tr><?php$gwc=$_SESSION["gwc"];//  echo $gwc[0][0];//echo'555';//echo $gwc[1][0];include_once("conn.php");// 包含数据库连接页$result=mysqli_query($conn,"select * from bgbiao ");// 执行查询操作并返回结果集//$gwc=mysqli_fetch_all($result);//echo $gwc[0][1];while($myrow=mysqli_fetch_object($result)){// 循环输出数据?><tr><td align="center"><span class="STYLE2"><?php echo $myrow->name; ?></span></td><td align="left"><span class="STYLE2"><?php echo $myrow->price; ?></span></td><td align="center"><span class="STYLE2"><?php echo $myrow->address; ?></span></td><td align="center"><span class="STYLE2"><?php echo $myrow->yu; ?></span></td><?phpecho "<td class='m_td'><a href='maincl.php?id={$myrow->id}' οnclick='add()'>加入购物车</a></td>";echo "</tr>";?></tr><?php}?>
<tr><td  colspan="3"><a href="gwc.php">查看购物车</a></td><td  colspan="2"><a href="user.php">查看账户</a></td>
</tr>
</table>
</body>
</html>

主页面处理:

maincl.php:

主要操作就是加入购物车的实现

<?php
/*** Created by PhpStorm.* User: dada* Date: 2019/6/4* Time: 11:57*/
session_start();
//
$id = $_GET["id"];
if(empty($_SESSION["gwc"]))
{//如果点击的购物车是空的(第一次添加)//如果购物车里是空的,造二维数组,$arr = array(array($id,1)//一维数组,取ids,第一次点击增加一个);$_SESSION["gwc"]=$arr;//扔到session里面
}
else//这里不是第一次点击
{//先判断购物车里是否已经有了该商品,用$id$arr = $_SESSION["gwc"];//把购物车的状态取出来$chuxian = false;
//定义一个变量;用来表示是否出现,默认是未出现foreach ($arr as $v) {//便利他//如果这里面有这件商品if ($v[0] == $id) //如果取过来的$v[0](商品的代号)等于$ids那么就证明购物车中已经有了这一件商品{$chuxian = true;//如果出现,直接把chuxian改成true}}if($chuxian){//购物车中有此商品for($i=0;$i<count($arr);$i++){if($arr[$i][0] == $id){//把点到的商品编号加1$arr[$i][1] += 1;}}$_SESSION["gwc"] = $arr;}else{//这里就只剩下:购物车里有东西,但是并没有这件商品$asg = array($id,1);//设一个小数组$arr[] = $asg;$_SESSION["gwc"]=$arr;}}
header("location:main.php")?>

 

购物车页面实现:

gwc.php:

<?php
/*** Created by PhpStorm.* User: dada* Date: 2019/6/3* Time: 21:20*/
$b=0;
?>
<!doctype html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport"content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>购物车</title>
</head>
<body>
<table align="center" border="1"><tr><td colspan="5" bgcolor="#a9a9a9" align="center">购物信息表</td></tr><tr><td>名称</td><td>价格</td><td>数量</td><td>操作</td></tr><?phpsession_start();if(!empty($_SESSION["gwc"])) {$arr = array();$arr = $_SESSION["gwc"];foreach ($arr as $v){include_once("conn.php");$sql = "select * from bgbiao WHERE id = '{$v[0]}'";$result=mysqli_query($conn,$sql);// 执行查询操作并返回结果集$att =mysqli_fetch_all($result);foreach ($att as $a) {$b = $b + $a[2] * $v[1];}}//造数组foreach ($arr as $v) {include_once("conn.php");// 包含数据库连接页$sql = "select * from bgbiao WHERE id = '{$v[0]}'";$result = mysqli_query($conn, $sql);// 执行查询操作并返回结果集$att = mysqli_fetch_all($result);foreach ($att as $a) {echo "<tr><td>{$a[1]}</td><td>{$a[2]}</td><td>{$v[1]}</td><td><a href='delete.php?id={$a[0]}'>删除</a> </td></tr> ";}}}?><tr><td colspan="2" >总价钱:<?phpecho $b;$_SESSION["qian"]=$b;?></td><td colspan="3" >您的余额:<?php$account=$_SESSION["account"];echo $account;?></td></tr><tr><td  colspan="5" align="center"><a href="tijiao.php">提交订单</a></td></tr>
</table>
</body>
</html>

购物车删除:

delete.php:

<?php
/*** Created by PhpStorm.* User: dada* Date: 2019/6/3* Time: 20:48*/
session_start();
$id = $_GET["id"];
$arr = $_SESSION["gwc"];
//var_dump($arr);
//取索引2(数量)
foreach ($arr as $key=>$v)
{if($v[0]==$id){if($v[1]>1){//要删除的数据$arr[$key][1]-=1;}else{//数量为1的情况下,移除该数组unset($arr[$key]);}}}$_SESSION["gwc"] = $arr;
//记得扔到session里面
header("location:gwc.php");
//删除完跳转回去

购物车提交与数据库数据交互操作:

tijiao.php:

<?php
/*** Created by PhpStorm.* User: dada* Date: 2019/6/4* Time: 13:09*/
session_start();
include ("conn.php");
//判断用余额是否满足
$name = $_SESSION["name"];
//获取到用户名
$aa=$_SESSION["qian"];//总价格
$account=$_SESSION["account"];
//判断余额是否满足
$ann=array();
if(!empty($_SESSION["gwc"]))
{$ann=$_SESSION["gwc"];}
$zhonglei = count($ann);
if($account>=$aa)
{//钱够,判断库存foreach($ann as $v){$sql = "select name,yu from bgbiao WHERE id='{$v[0]}'";//代号$v[0]$result=mysqli_query($conn,$sql);// 执行查询操作并返回结果集$akc =mysqli_fetch_all($result);$akc[0][1];//库存//比较是否满足库存// echo $akc[0][0];//  echo $akc[0][1];// echo $v[1];if($akc[0][1]<$v[1]){echo "{$akc[0][0]}库存不足";//退出header("location:gwc.php");exit;}}
//提交订单:
//i.    从用户账户中扣除本次购买的总价格
//ii.    从商品库存中扣除本次每种商品的购买数量
//iii.    向订单表和订单内容表中加入本次购买的商品信息//扣除账户余额$sql1 = "update login set account = account-{$aa} WHERE username = '{$name}'";$result=mysqli_query($conn,$sql1);// 执行查询操作并返回结果集//扣除库存foreach($ann as $v){$sql2= "update bgbiao set yu = yu-{$v[1]} WHERE id='{$v[0]}'";//代号$v[0]$result=mysqli_query($conn,$sql2);// 执行查询操作并返回结果集}$_SESSION["gwc"]=null;$_SESSION["account"]=$account-$aa;header("location:main.php");
}
else
{echo "钱不够";header("location:gwc.php");exit;}

 查看账户页面:

 

user.php:

<?php
/*** Created by PhpStorm.* User: dada* Date: 2019/6/3* Time: 21:39*/
?>
<!doctype html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport"content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>个人信息浏览</title>
</head>
<body>
<table align="center" border="1"><tr><td colspan="2" bgcolor="#a9a9a9" align="center">个人信息表</td></tr><tr><td>姓名</td><td>余额</td></tr><?phpsession_start();//   $_SESSION["name"]='dadada';$name =$_SESSION["name"];//echo $_SESSION["name"];include_once("conn.php");// 包含数据库连接页$result=mysqli_query($conn,"select id,username,account from login where username='{$name}'");// 执行查询操作并返回结果集if (!$result) {printf("Error: %s\n", mysqli_error($conn));exit();}while($myrow=mysqli_fetch_object($result)){// 循环输出数据?><tr><td align="center"><span class="STYLE2"><?php echo $myrow->username; ?></span></td><td align="left"><span class="STYLE2"><?php echo $myrow->account; ?></span></td></tr><tr><?phpecho "<td class='m_td'><a href=useradd.php>充值</a></td><td><a href=userupdatepassword.php>改密码</a></td>";echo "</tr>";?><?php}?>
</table>
</body>
</html>

用户更改密码操作实现:

userupdatepassword.php:

 

<?php
/*** Created by PhpStorm.* User: dada* Date: 2019/6/4* Time: 9:18*/
session_start();
$name =$_SESSION["name"];
?>
<!doctype html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport"content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>改密码</title>
</head>
<body>
<form action="userupdatepasswordcl.php" method="post"><table border="1" align="center"><tr><td colspan="2" align="center" bgcolor="#a9a9a9">改密码</td></tr><tr><td>姓名:</td><td><?php echo $name ;?></td></tr><tr><td>新密码:</td><td><input type="password" name="password1" ></td></tr><tr><td>再次输入新密码:</td><td><input type="password" name="password2" ></td></tr><tr><td align="center"><input type="submit" value="改密码" align="center"></td><td align="center"><input type="reset" value="重置"></td></tr></table>
</form>
</body>
</html>

改密码处理操作:

userupdatepasswordcl.php:

<?php
/*** Created by PhpStorm.* User: dada* Date: 2019/6/4* Time: 9:22*/
session_start();
$name =$_SESSION["name"];
include_once("conn.php");
if (!($_POST['password1'] )||!($_POST['password2'] )){echo "<script>alert('输入不允许为空');history.go(-1);</script>";
}
else {$password1=$_POST['password1'];$password2=$_POST['password2'];if($password1==$password2){$sqlstr2 = "update login set password ='{$password1}' where username='{$name}'";$result2 = mysqli_query($conn, $sqlstr2);if ($result2) {echo "<script>alert('改密成功');location='login.php';</script>";} else {echo "<script>alert('改密失败');history.go(-1);</script>";}}else{echo "<script>alert('俩次密码不一致');history.go(-1);</script>";}
}
?>

用户充值页面:

useradd.php:

<?php
/*** Created by PhpStorm.* User: dada* Date: 2019/6/4* Time: 8:46*/
session_start();
$name =$_SESSION["name"];
//echo $_SESSION["name"];
//include_once("conn.php");
//$result=mysqli_query($conn,"select account from login where id='{$id}'");// 执行查询操作并返回结果集
?>
<!doctype html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport"content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>充值</title>
</head>
<body>
<form action="useraddcl.php" method="post"><table border="1" align="center"><tr><td colspan="2" align="center" bgcolor="#a9a9a9">充值</td></tr><tr><td>姓名:</td><td><?php echo $name ;?></td></tr><tr><td>充值:</td><td><input type="number" name="qian" ></td></tr><tr><td></td><td align="center"><input type="submit" value="充值" align="center"><input type="reset" value="重置"></td></tr></table>
</form>
</body>
</html>

useraddcl.php:

<?php
/*** Created by PhpStorm.* User: dada* Date: 2019/6/4* Time: 8:59*/
session_start();
$name =$_SESSION["name"];
include_once("conn.php");
if (!($_POST['qian'] )){echo "<script>alert('输入不允许为空');history.go(-1);</script>";
}else {$qian=$_POST['qian'];$sqlstr1 = "select account from login where username='{$name}'";$result1 = mysqli_query($conn, $sqlstr1);$rows = mysqli_fetch_row($result1);//将查询结果返回为数组$number=$rows[0];echo $number;$acc=$number +$qian;$sqlstr2 = "update login set account ='{$acc}' where username='{$name}'";$result2 = mysqli_query($conn, $sqlstr2);if ($result2) {echo "<script>alert('充值成功');location='user.php';</script>";} else {echo "<script>alert('充值失败');history.go(-1);</script>";}
}
?>

  

 

转载于:https://www.cnblogs.com/gonT-iL-evoL-I/p/10973335.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.luyixian.cn/news_show_822361.aspx

如若内容造成侵权/违法违规/事实不符,请联系dt猫网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

windows 变网站服务器,windows+IIS6安装及搭建网站服务器环境教程

一、安装IIS1、如系统中还未安装IIS服务器&#xff0c;可打开“控制面板”&#xff0c;然后单击启动 “添加/删除程序”&#xff0c; 在弹出的对话框中选择 “添加/删除Windows组件”&#xff0c;在Windows组件向导对话框中选中“Internet信息服务(IIS)”&#xff0c;然后单击“…

程序员一些实用的网站收藏

程序员一些实用的网站收藏 1. 面试 两个网站 1.1牛客网 牛客网 https://www.nowcoder.com/ 1.2力扣 力扣 https://leetcode-cn.com/ 2 查资料的网站&#xff08;包含在线工具&#xff09; 2.1 程序员的工具箱 程序员的工具箱 https://tool.lu/ 2.2 菜鸟教程 菜鸟教…

nodejs后端 转 php,PHP+NodeJs后端给网站截图

有些导航站提交网站后会把网站截图并且在详情页会附带网页截图&#xff0c;例如这个 博客大全&#xff1a;blogwe.com挺好奇怎么实现的&#xff0c;所以了解到了这两个开源项目&#xff1a;Puppeteer 和 PuPHPeteer注意&#xff1a;需要安装 NodeJs 8 的版本设置 NodeJs 镜像(如…

在桌面点击html文档跳转到指定网站

在windows桌面新建一个html文档&#xff0c;然后文档内容如下&#xff1a; <script language"javascript">location.replace("https://www.baidu.com"); </script> 然后点击百度.html&#xff0c;就会打开浏览器并跳转到百度。

C++] WAP GPRS 向WWW网站 提交POST GET 数据 实例

代码 ///接收程序ASP<%numrequest("num")passrequest("pass")setfsserver.CreateObject("Scripting.FileSystemObject")setfilefs.OpenTextFile(server.MapPath("http.txt"),8,True)file.writeline num"---""-"…

SEO图片测试,alt=ddd title= 就不显示alt 内容

转载于:https://www.cnblogs.com/avatar/archive/2011/07/14/2106614.html

使用HTML5,CSS3和jQuery增强网站用户体验

记 得几年前如果你需要添加一些互动元素到你的网站中用来改善用户体验&#xff1f; 是不是立刻就想到了flash实现&#xff1f;这彷佛年代久远的事了。使用现在最流行的web技术 HTML5&#xff0c;CSS3和jQuery&#xff0c;同样也可以实现类似的用户体验。而且使用这些特性将会比…

2011年回顾:改变游戏的20个HTML5网站

今年HTML5确实给我们带来了很大的冲击。HTML5 Doctors&#xff0c;Oli Studholme评选出了20个最佳网站&#xff0c;它们涵盖了语义、音频、客户端web apps、canvas以及SVG和WebGL&#xff0c;这些网站预示了未来web的发展方向。 对HTML5和web来说&#xff0c;今年是收获丰富的一…

如何获取网站服务器运行状态

在学习的过程中总要经历一些痛苦的过程才能达到想要达到的地方。前几天牛人给我出了一道题&#xff0c;说是让我写一段程序判断一个网站的服务器是否正常运行。本着我自己先仔细研究实在不行再问的原则我各种郁闷了好几天。 各种没头绪&#xff0c;虽然磕磕绊绊的找到了一个网址…

Myeclipse+Tomcat运行网站

1、新建网站项目 2、在Myeclipse中设置Tomcat路径 window-->preferences&#xff0c;在左侧的输入框中输入tomcat&#xff0c;回车。 3、运行项目 右键单击刚刚创建的项目 4、在浏览器中输入URL http://localhost:8080/FirstWebTest/ 即可见到刚刚创建的网页。

收藏网站制作常用经典ajax.prototype.javascript实例打包下载

ajax.prototype.javascript实例打包下载..不错不错&#xff0c;都是我喜欢的~。 保存在这里拉~。大家喜欢可以拿去下载。 点击下载&#xff1a;5右拖动--多选框控制显示和不显示列.rar 点击下载&#xff1a;ajax-FileUpload.rar 点击下载&#xff1a;ajax-tab.rar 点击下载&…

使用recon/domains-hosts/baidu_site模块,枚举baidu网站的子域

使用recon/domains-hosts/baidu_site模块&#xff0c;枚举baidu网站的子域 【实例3-1】使用recon/domains-hosts/baidu_site模块&#xff0c;枚举baidu网站的子域。具体操作步骤如下所示&#xff1a;本文选自Kail Linux渗透测试实训手册 &#xff08;1&#xff09;使用recon/do…

我的网站后台管理系统 - 权限系统的设计

直入正题&#xff0c;本文只谈思路&#xff0c;不谈具体代码及实现以目前我所遇到的权限需求&#xff0c;以及本人肤浅的见识&#xff0c;研究结果如下&#xff1a;后台的权限控制大概分为两类1. 我能干什么2. 我能干哪些我能干什么&#xff0c;决定了我能做的操作是什么&#…

网站重构之配置文件分解

最近赶上公司重构网站,架构组的同事为提高web部门的开发效率,总结出了一些不错的经验&#xff0c;本人也是直接受益者&#xff0c;为此用下面几篇文章来与大家分享。 这一篇&#xff0c;我想讨论的是网站配置文件问题。说到配置文件&#xff0c;我第一印象就是它的灵活性&#…

springboot创建一个新的项目(通过spring官方网站)

本文主要介绍如何通过spring官方网站创建一个spring boot的项目。 好&#xff0c;下面上货。 1、首先进入spring的网站https://start.spring.io/这个是一个偏向简洁默认的一个方式&#xff0c;也可以点击“switch to the full version”&#xff0c;那样能够看到所有配置的选项…

IronPython 个人网站样例----宝藏挖掘

IronPython for ASP.NET 的 CTP 已经发布两个多星期了&#xff0c;惭愧的是&#xff0c;因为工作繁忙&#xff0c;一直没有太多时间来学习。居然忽略了 Personal Web Site Starter Kit 的 IronPython 样例。幸亏了 Scott Guthrie 这篇博客:http://blog.joycode.com/scottgu/arc…

35个富有启发和美丽的红色网站案例

网站设计是设计师的具有挑战性的任务。&#xff0c;他们设计的网站&#xff0c;即他们应该选择什么颜色风格来进行网站设计&#xff0c;这是每一个网站设计最重要的部分。颜色总是定义您的网站的性质。 有各种颜色的网站&#xff0c;如蓝色&#xff0c;绿色&#xff0c;灰色&am…

AX 2012 安装EP时提示网站模板“AXSITEDEF#0”的文件或参数无效

问题 在Dynamics AX 2012 安装Enterprise Portal 时最后配置阶段提示错误&#xff0c;信息如下&#xff1a; The site /sites/DynamicsAx could not be created. The following exception occurred: 网站模板“AXSITEDEF#0”的文件或参数无效。 参数名: WebTemplate. 仅当Busi…

minify php,php开源系统-使用Minify来优化网站性能

1 对php网站进行了搭建&#xff0c;并完成一些对图片上传的基本功能&#xff0c;服务器数据库的操作等等2 完成 首个jquery 框架中静态模板中加入 实际的函数范例&#xff1b;并了解和掌握了 sizzle.js 框架的使用流程和机制&#xff1b;并成功的在本地apache服务器站点上进行引…

现实世界的Windows Azure:专访PrivacyCentral网站创始人、CEO Zoiner Tejada

作为现实世界Windows Azure博客系列中的一部分&#xff0c;我联系了PrivacyCentral网站创始人、CEO Zoiner Tejada&#xff0c;来探寻该公司是如何利用Windows Azure平台及Ruby语言来搭建其强大的在线隐私服务。点击这里来了解PrivacyCentral的成功案例。下面我们来看看Tejada先…