<?php
$good = $_GET["q"];//获取数据
if(isset($_COOKIE["name"],$_COOKIE["pwd"])==true)
{
$shopna=$_COOKIE["name"];
$shoppw=$_COOKIE["pwd"];
$con = mysqli_connect("192.168.43.251:3306","admin","admin","mydb");
if (!$con)
{
die('Could not connect: ' . mysqli_error($con));
}
mysqli_query($con , "set names utf8");// 设置编码,防止中文乱码,关键
$result = mysqli_query($con, "SELECT * FROM resident WHERE ID = '$shopna' AND password = '$shoppw' ");
if ($result)
{
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
{
$res_credit =$row['credit'];
}
$result = mysqli_query($con, "SELECT * FROM goods WHERE good_name = '$good' ");
if($result)
{
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
{
$good_price = $row['good_cost'];
$good_sum = $row['good_sum'];
}
if( $good_sum >0)
{
if($res_credit>=$good_price)
{
$remain=$res_credit-$good_price;
$order_cmd = "INSERT INTO order_list(buyer,good) VALUES('$shopna','$good')";
$result=mysqli_query($con,$order_cmd);
if($result)
{
//更新居民表
$result=mysqli_query($con,"UPDATE resident SET credit='$remain' WHERE ID = '$shopna'");
if($result)
{
//更新商品表
$result=mysqli_query($con,"UPDATE goods SET good_sum=good_sum-1 WHERE good_name = '$good'");
if($result)
{
echo "<script language=\"JavaScript\">";
echo "alert(\"兑换成功,你当前剩余积分:$remain\\n\你的订单已生成,请耐心等待配送\");history.back();</script>";
}
}
}
}
else
{
echo "<script language=\"JavaScript\">";
echo "alert(\"你的积分不足,当前积分:$res_credit\");history.back();</script>";
}
}
else
{
echo "<script language=\"JavaScript\">";
echo "alert(\"该商品库存不足,当前库存:$good_sum\");history.back();</script>";
}
}
mysqli_free_result($result);
}
}
else
{
echo "<script language=\"JavaScript\">";
echo "alert(\"你还没有登录\");history.back();</script>";
}
?>
G果
- 粉丝: 8167
- 资源: 29
最新资源
- (源码)基于C语言的系统服务框架.zip
- (源码)基于Spring MVC和MyBatis的选课管理系统.zip
- (源码)基于ArcEngine的GIS数据处理系统.zip
- (源码)基于JavaFX和MySQL的医院挂号管理系统.zip
- (源码)基于IdentityServer4和Finbuckle.MultiTenant的多租户身份认证系统.zip
- (源码)基于Spring Boot和Vue3+ElementPlus的后台管理系统.zip
- (源码)基于C++和Qt框架的dearoot配置管理系统.zip
- (源码)基于 .NET 和 EasyHook 的虚拟文件系统.zip
- (源码)基于Python的金融文档智能分析系统.zip
- (源码)基于Java的医药管理系统.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈