以下は私のコードです:
<?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);
}
?>
私の状況では、システムが「カード」に新しいレコードを作成し、それに応じて「償還」テーブルを更新する必要があります..
ただし、新しいカードを作成することしかできませんでしたが、「償還」テーブルを更新することはできません...誰か助けてくれますか? これを調べるために必要なことを教えてください...ありがとう!
私が試してみました
$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ファイルで、必要なデータを取得できます...しかし、更新されない理由がわかりません ><