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

时间:2016-02-09 20:43:18

标签: php html mysql sql

<?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'附近使用正确的语法

1 个答案:

答案 0 :(得分:6)

username = '$username'之后缺少逗号。

查询应如下所示:UPDATE users SET username = '$username', password = '$password' WHERE id = $id