我有一个基于奖励积分的网站,用户需要更新奖励积分才能在门户网站上购物。他使用过的代码将从数据库中删除。如果用户尝试再次使用该代码且该代码已被使用,我如何才能显示错误消息。
enter code here
<?php
if(isset($_POST['sub'])){
$db_host="localhost";
$db_username="root";
$db_password="";
$db_name="bs1";
$con=mysql_connect("$db_host", "$db_username", "$db_password") or die("could not connect to mysql!!!");
if($con=="")
{
echo "Database not connected!!!!";
}
else
{
$isdb=mysql_select_db("$db_name") or die("database not available!!!!");
if($isdb=="")
{
echo "database not selected!!!!";
}
else
{
$emp_ID=$_POST['emp_ID'];
$code=$_POST['code'];
$query = mysql_query("select * from oc_sand_reward where `Code`='$code'") or die (mysql_error());
$data=mysql_fetch_assoc($query);
$code_db=$data['Code'];
$points_db=$data['Point'];
if($code==$code_db)
{
$query1 = mysql_query("select * from oc_customer where `emp_ID`='$emp_ID'") or die (mysql_error());
$data1=mysql_fetch_assoc($query1);
$customer_id=$data1['customer_id'];
$query2=mysql_query("INSERT INTO `oc_customer_reward` (customer_id, emp_ID, emp_name, order_id, description, Code, points, date_added) VALUES ($customer_id, $emp_ID, '$emp_name', 0, 'rewarded', '$code', $points_db, NOW());");
$query4=mysql_query("INSERT INTO `oc_customer_reward_history` (customer_id, emp_ID, description, Code, points) VALUES ($customer_id, $emp_ID, 'rewarded', '$code', $points_db)");
$query3=mysql_query("DELETE FROM oc_sand_reward WHERE Code='$code'");
header("location:http://localhost/bsl/index.php?route=account/account");
exit();
}
else
{
}
}
}
}
?>
最佳答案
如果您想在使用后删除它,您可以按照 Daan 的说法或创建另一个名为 used_points
的表。
在使用奖励积分后,您可以构造一个查询,将已使用的积分移至表 used_points
中。
然后,每当用户尝试加载结果点时,您就可以根据 used_points
表中的值对其进行验证
关于php - 如何在 my_sql 查询中添加错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30300695/