下面是我的代码:
<?php
$response = array();
if ($_POST['code_input'] != ''){
$code_input = $_POST['code_input'];
$email_code = $_POST['email_code'];
$link = mysql_connect('localhost','root','') or die ('Could not connect: '.mysql_error());
mysql_select_db('ichop') or die ('Could not connect to database');
//check if redemption code exist
$exist = mysql_query("select * from redemption where red_code = '$code_input'");
//check if redemption code is usable
$usable = mysql_query("select * from redemption where code_status = 'usable' and red_code = '$code_input'");
//check if users already have the card
$possess = mysql_query("select * from customer customer join card card on customer.customer_id = card.customer_id join redemption redemption on card.merchant_id = redemption.merchant_id where card.merchant_id = redemption.merchant_id and redemption.red_code = '$code_input'");
//check if reward name is "reward point"
$point = mysql_query("SELECT * FROM redemption redemption JOIN reward reward ON redemption.merchant_id = reward.merchant_id WHERE reward.reward_name LIKE '%point%' AND redemption.red_code = '$code_input'");
$data3 = mysql_fetch_array($point);
$customer = mysql_query("select * from customer where C_email = '$email_code'");
$data1 = mysql_fetch_array($customer);
$merchant = mysql_query("select * from redemption where red_code = '$code_input'");
$data2 = mysql_fetch_array($merchant);
$card = mysql_query("select redemption.Total_Point, card.card_id from customer customer join card card on customer.customer_id = card.customer_id join redemption redemption on card.merchant_id = redemption.merchant_id where redemption.red_code = '$code_input'");
$data4 = mysql_fetch_array($card);
if(mysql_num_rows($exist) == 1){
if(mysql_num_rows($usable) == 1){
if(mysql_num_rows($possess) == 1){
} else {
//create new card for customer
$create = mysql_query("INSERT INTO card (Card_ID, Chop_Amt, Customer_ID, Merchant_ID) VALUES ('', '0', '".$data1["Customer_ID"]."', '".$data2["Merchant_ID"]."')");
if(mysql_num_rows($point) == 1){
//update the chop amount in card details
$update1 = mysql_query("UPDATE card SET Chop_Amt = '".$data3["Total_Point"]."' where Customer_ID = '".$data1["Customer_ID"]."' and Merchant_ID = '".$data2["Merchant_ID"]."'");
$update2 = mysql_query("UPDATE redemption SET Code_Status = 'Unusable', Red_Date = now(), Point_Balance = '".$data3["Total_Point"]."', Card_ID = '".$data4["Card_ID"]."' where red_code = '$code_input'");
$response["success"] = 1;
$response["message"] = "Code redeemed!";
echo json_encode($response);
} else {
$response["success"] = 0;
$response["message"] = "You do not have enough point to use the code!";
echo json_encode($response);
}
}
} else {
//error for non-usable code
$response["success"] = 0;
$response["message"] = "Code is not usable!";
echo json_encode($response);
}
} else {
//error for non existing code
$response["success"] = 0;
$response["message"] = "Code does not exist!";
echo json_encode($response);
}
} else {
//error for blank field
$response["success"] = 0;
$response["message"] = "Please fill in the code field!";
echo json_encode($response);
}
?>
我的情况是,如果他们没有 1,我希望我的系统在“卡”中创建一个新记录,然后相应地更新“兑换”表..
但是,我只设法创建了一张新卡,但无法更新“兑换”表……有人可以帮我吗?请告诉我您需要检查的任何事情...谢谢!
我努力了
$card = mysql_query("select redemption.Total_Point, card.card_id from customer customer
join card card on customer.customer_id = card.customer_id
join redemption redemption on card.merchant_id = redemption.merchant_id
where redemption.red_code = '$code_input'");
$data4 = mysql_fetch_array($card);
在一个单独的 php 文件中,我可以获得我想要的数据...但是我不明白为什么它没有更新><