我正在從MySql數據庫上的手機遊戲中保存遊戲狀態。這些信息已成功保存,但這反映了保存遊戲狀態時出現錯誤。我仍然在調整php,不確定這是從哪裏來的。功能返回假陰性
PS我知道SQL語句是不安全的。現在我只是把基礎知識運行起來,因爲陳述和表格本身很快就會改變。
Listining傳入JSON:
} else if ($tag == 'save_game_state') {
$email = $_POST['email'];
$virtumon = $_POST['monster'];
$qty = $_POST['qty'];
$exp = $_POST['exp'];
$user = $db->saveGameState($email, $monster, $qty, $exp);
if ($user) {
$response["success"] = 1;
$response["The game state has been successfully saved"];
echo json_encode($response);
} else {
// user failed to store
$response["error"] = 1;
$response["error_msg"] = "Error occured in saving the game state";
echo json_encode($response);
}
將信息輸入到數據庫並返回成功/失敗。
public function saveGameState($email, $monster, $qty, $exp) {
$result = mysql_query("INSERT INTO user_profiles(email, monster, qty, exp) VALUES('$email', '$monster', '$qty', '$exp')") or die(mysql_error());
// TODO check for successful store
$success = mysql_query("SELECT email, monster, qty, exp FROM user_profiles WHERE email = '$email' AND monster= '$monster' AND qty = '$qty' AND exp = '$exp'");
if ($success) {
return mysql_fetch_array($success);
} else {
return false;
}
}
@ DanielA.White請閱讀整個POST「PS我知道SQL語句是不安全的。現在,我剛開基本面和運行作爲自己很快就會改變報表和表格。」 !! ! – KDEx
@ DanielA.White:KDEx提到他已經知道...... – teynon