php - Insert varchar coupon code in database table -
i have website based on reward point. want store 'coupon code' in database record user has used code recharge account buy anything. create insert table in php
insert coupon user.
i encountered problem insert into
sql syntax insert int
code database when use varchar
code recharge account not storing data...
examples:
int coupon code: 22334466
int coupon code: su5c5e6s
<?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 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 * oc_abhi_reward `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 * oc_customer `emp_id`='$emp_id'") or die (mysql_error()); $data1=mysql_fetch_assoc($query1); $customer_id=$data1['customer_id']; $query2=mysql_query("insert `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 `oc_customer_reward_history` (customer_id, emp_id, description, code, points) values ($customer_id, $emp_id, 'rewarded', $code, $points_db)"); $query3=mysql_query("delete oc_abhi_reward code='$code'"); header("location:http://localhost/bsl/index.php?route=account/account"); exit(); } else { } } } } ?> <!--php code reward entry end-->
$code should write in single quotes , code insert variable character codes in database should this,
$query4=mysql_query("insert `oc_customer_reward_history` (customer_id, emp_id, description, code, points) values ($customer_id, $emp_id, 'rewarded', '$code', $points_db)");
Comments
Post a Comment