我在我的Android应用程序上成功注册。但不知何故,我真的想用PHP更新我注册的用户信息。但是,我失败了。我工作的代码有什么问题。
<?php
$host = 'example.com';
$user = 'username';
$pass = 'password';
$db = 'database';
$con = mysqli_connect($host, $user, $pass, $db);
if (!$con) {
printf("Connection failed: %s\n", mysqli_connect_error());
exit();
}
$query ="UPDATE user_info VALUES (?, ?, ?, ?, ?, ?)"; // make this query into "update query"
$statement = mysqli_prepare($con, $query);
if($statement === FALSE){ die(mysqli_error($link)); }
mysqli_stmt_bind_param($statement, "isssss" ,$UserID, $LastName, $FirstName, $Username, $EmailAddress, $Password);
$LastName = $_POST["LastName"];
$FirstName = $_POST["FirstName"];
$Username = $_POST["Username"];
$EmailAddress = $_POST["EmailAddress"];
$Password = $_POST["Password"];
mysqli_stmt_execute($statement);
$response = array();
$response["success"] = true;
echo json_encode($response);
?>
顺便说一句,我通过简化问题完成了这个问题。
答案 0 :(得分:0)
您应该在绑定它们之前设置变量的值:
<?php
//I remove your credentials
$con = mysqli_connect($host, $user, $pass, $db);
if (!$con) {
printf("Connection failed: %s\n", mysqli_connect_error());
exit();
}
$query ="UPDATE user_info SET lastname = ? AND firstname = ? AND username = ? AND emailaddress = ? AND password = ? WHERE userid = ?"; // make this query into "update query"
$statement = mysqli_prepare($con, $query);
if($statement === FALSE){ die(mysqli_error($link)); }
$LastName = $_POST["LastName"];
$FirstName = $_POST["FirstName"];
$Username = $_POST["Username"];
$EmailAddress = $_POST["EmailAddress"];
$Password = $_POST["Password"];
mysqli_stmt_bind_param($statement, $LastName, $FirstName, $Username, $EmailAddress, $Password, $UserID);
mysqli_stmt_execute($statement);
$response = array();
$response["success"] = true;
echo json_encode($response);
编辑 $UserID
未定义。你的UPDATE语句是完全错误的