Php 如何在my_sql查询中添加错误消息
我有一个基于奖励点的网站,用户需要更新奖励点,以便在门户网站上购物。他使用过的代码将从数据库中删除。如果用户试图再次使用该代码,并且该代码已被使用,我如何显示错误消息Php 如何在my_sql查询中添加错误消息,php,mysql,Php,Mysql,我有一个基于奖励点的网站,用户需要更新奖励点,以便在门户网站上购物。他使用过的代码将从数据库中删除。如果用户试图再次使用该代码,并且该代码已被使用,我如何显示错误消息 enter code here <?php if(isset($_POST['sub'])){ $db_host="localhost"; $db_username="root"; $db_password=""; $db_name="bs1"; $con=mysql_connect
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 says或创建另一个名为“可能已使用的点”的表 在这里,使用奖励点后,您可以构造一个查询,将使用的点移动到表used_points中
然后,每当用户尝试加载结果点时,您都要根据used_points表中的值验证结果点mysql不推荐使用,您应该使用mysqli或PDO。在oc_sand_奖励表中添加一个布尔列。如果使用,请将该值设置为true。是的,我已使用名为oc_customer_reward的表,其中存储了使用过的代码,并将其从表oc_sand_reward中删除,因此用户在使用代码后无法使用。但问题是,如果有人试图再次使用使用过的代码,则不会显示任何警告消息。因此,我想显示一条消息,说明您正在尝试的代码已被使用。如果用户正在尝试使用已使用的代码,我如何显示此消息。然后,生成一个查询,以选择oc_sand_奖励表中所有未使用的代码,其中包含未使用代码的字段=“用户输入代码”。然后确定返回的行数。因此,如果行数==0,则回显或分配一个错误变量,此代码已被使用。我希望你现在明白了也许$user\u input\u code=$\u POST['raward\u point']从oc_和_奖励中选择奖励积分,其中奖励积分=“$user_input_code”。所以,如果mysqli_num_rows$query返回零或false,则表示它已被使用