在数据库中插入 varchar 优惠券代码 table

Insert varchar coupon code in database table

我有一个基于奖励积分的网站。我想将 'coupon code' 存储在数据库中,记录哪个用户使用了哪个代码来为他们的帐户充值以购买任何东西。我在 php 中创建了一个插入 table 来为用户插入优惠券。

我遇到了一个问题,INSERT INTO sql 语法只将 int 代码插入数据库,但是当我们使用 VARCHAR 代码为帐户充值时,它没有存储任何数据...

示例:


<?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_abhi_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,  order_id, description, points, date_added) VALUES ($customer_id, $emp_ID,  0, 'rewarded', $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_abhi_reward WHERE Code='$code'");
            header("location:http://localhost/bsl/index.php?route=account/account");
            exit();
            }
            else
            {

            }           
        }
    }
}
?>
<!--php code for reward entry END-->

$code要写在单引号里,所以数据库中插入可变字符代码的代码应该是这样的,

$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)");