您的SQL语法有错误;检查与MariaDB服务器版本对应的手册以获得正确的语法

时间:2021-07-12 00:58:12
<?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>

Output result: Failed

输出结果:失败

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'password = 'ffffffffffff' WHERE id = 1' at line 1

您的SQL语法有错误;检查与MariaDB服务器版本对应的手册,找到正确的语法,在第1行使用“password =”附近的“ffffffffffffffffff”,其中id = 1

1 个解决方案

#1


4  

It's missing a comma after username = '$username'.

它在username = '$username'后面缺少一个逗号。

The query should look like: UPDATE users SET username = '$username', password = '$password' WHERE id = $id

查询应该是这样的:更新用户设置用户名= '$username',密码= '$password', id = $id。

#1


4  

It's missing a comma after username = '$username'.

它在username = '$username'后面缺少一个逗号。

The query should look like: UPDATE users SET username = '$username', password = '$password' WHERE id = $id

查询应该是这样的:更新用户设置用户名= '$username',密码= '$password', id = $id。