我想更新使用PHP这是在logcat中diplayed错误在数据库中的数据更新mysql中的数据是错误使用PHP
Error: UPDATE usersSET Question1=null2null,Question3=nullnull,Question4=nullnullnullnullWHERE email=bb<br>You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '=null2null,Question3=nullnull,Question4=nullnullnullnullWHERE email=bb' at line 1{"error":false,"uid":"56bd5f88afb7b3.99372648","user":{"name":"Bb","email":"bb","created_at":"2016-02-12 09:58:56","updated_at":null,"Question1":"","Question3":"","Question4":""}
的问题1,问题3和问题4列中的值不会得到更新,它应该分别为null2null,nullnull,nullnullnullnull。它被写入检查您的版本的语法,我在本地运行5.5.12 php版本和5.6.17 mysql版本。我检查了语法和不同的网站上显示的不同显示不同的syntasx如何得到正确的,下面是我的PHP代码
PHP
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "android_api";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
require_once 'include/DB_Functions.php';
$db = new DB_Functions();
// json response array
$response = array("error" => FALSE);
if (isset($_POST['Question1']) && isset($_POST['Question3']) && isset($_POST['Question4'])) {
// receiving the post params
$email = $_POST['email'];
$password = $_POST['password'];
$Question1 = $_POST['Question1'];
$Question3 = $_POST['Question3'];
$Question4 = $_POST['Question4'];
/*$sql = "INSERT INTO users (Question1, Question2, Question4)
VALUES ('$Question1', '$Question3', '$Question4')"; */
$user = $db->getUserByEmailAndPassword($email, $password);
// $result = mysql_query("UPDATE users"."SET Question1='$Question1',Question3='$Question3',Question4='$Question4'"."WHERE email=$email";
$sql="UPDATE users"."SET Question1=$Question1,Question3=$Question3,Question4=$Question4"."WHERE email=$email";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
// get the user by email and password
$user = $db->getUserByEmailAndPassword($email, $password);
if ($user != false) {
// use is found
$response["error"] = FALSE;
$response["uid"] = $user["unique_id"];
$response["user"]["name"] = $user["name"];
$response["user"]["email"] = $user["email"];
$response["user"]["created_at"] = $user["created_at"];
$response["user"]["updated_at"] = $user["updated_at"];
$response["user"]["Question1"] = $user["Question1"];
$response["user"]["Question3"] = $user["Question3"];
$response["user"]["Question4"] = $user["Question4"];
echo json_encode($response);
} else {
// user is not found with the credentials
$response["error"] = TRUE;
$response["error_msg"] = "ABCD";
echo json_encode($response);
}
} else {
// required post params is missing
$response["error"] = TRUE;
$response["error_msg"] = "abcd";
echo json_encode($response);
}
?>
编辑
阅读答案后现在更改语法错误更改为
Error: UPDATE users SET Question1=null2null,Question3=nullnull,Question4=nullnullnullnull WHERE email=bb<br>Unknown column 'bb' in 'where clause'{"error":false,"uid":"56bd5f88afb7b3.99372648","user":{"name":"Bb","email":"bb","created_at":"2016-02-12 09:58:56","updated_at":null,"Question1":"","Question3":"","Question4":""}}
users'和'SET' –