更新記錄是我的代碼:麻煩在mysql數據庫下面
<?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文件,我可以得到我想要的數據。不過我逼債瞭解它爲什麼不更新> <
它進入塊? select語句是否返回預期值? – draxxxeus
嘗試調試:'$ update2 = mysql_query(「UPDATE redemption SET Code_Status ='Unusable',Red_Date = now(),Point_Balance ='」。$ data3 [「Total_Point」]。'',Card_ID ='「。$ data4 [「Card_ID」]。「'其中red_code ='$ code_input'」)或die(mysql_error());'也請記住'mysql_ *'函數已棄用,最好使用'mysqli'或'PDO' – Fabio
@draxxxeus ,如果我手動控制更改值..它正在工作...我試圖運行另一個PHP文件中的選擇語句...它顯示錯誤和total_point –