如何在my_sql查询中添加错误消息

时间:2015-05-18 10:23:30

标签: php mysql

我有基于奖励积分的网站,用户需要在网站门户上更新奖励积分。他使用的代码将从数据库中删除。如果用户再次尝试使用该代码已经使用过代码,我怎么能显示错误消息。

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
            {

            }           
        }
    }
}
?>

1 个答案:

答案 0 :(得分:0)

如果您想在删除后删除它,您可以确实想要Daan说或创建另一个名称可能为used_points的表。

在使用奖励积分之后,您可以构建查询以将使用的点移动到表used_points中。

然后,只要用户尝试加载结果点,就会根据used_points表中的值对其进行验证

相关问题