<?php
$connection = mysqli_connect("localhost","root","","loginapp");
if(!$connection){
echo "Connection Failed.";
}
$query = "SELECT * FROM users";
$result = mysqli_query($connection,$query);
if(!$result){
die("Query dismissed".mysqli_error($connection));
}
if(isset($_POST['submit'])){
$username = $_POST['name'];
$password = $_POST['password'];
$id = $_POST['id'];
$query = "UPDATE users SET username = '$username' password = '$password' WHERE id = $id ";
$result = mysqli_query($connection, $query);
if(!$result){
die("Query FAILED" . mysqli_error($connection));
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<form action = "Update.php" method = "post">
<input type = "name" name = "name" placeholder = "Type your name">
<input type = "password" name = "password" placeholder = "Type your password"><br>
<select name="id" id="">
<?php
while($row = mysqli_fetch_assoc($result)){
$id = $row["id"];
echo "<option value='$id'>$id</option>";
}
?>
</select>
<input type = "submit" name = "submit" value = "Update">
</form>
</body>
</html>
输出结果:失败
您的SQL语法有错误;检查与MariaDB服务器版本对应的手册,以便在第1行'password ='ffffffffffff'WHERE id = 1'附近使用正确的语法
答案 0 :(得分:6)
在username = '$username'
之后缺少逗号。
查询应如下所示:UPDATE users SET username = '$username', password = '$password' WHERE id = $id