手册中的错误与您的MariaDB服务器版本相对应,语法正确

时间:2019-10-09 07:25:46

标签: php sql mariadb

我不知道为什么会出现错误,只是添加一个新列。

<?php

    $Title    = $_POST['title'];
    $First    = $_POST['first'];
    $Middle   = $_POST['middle'];
    $Last     = $_POST['last'];
    $Address1 = $_POST['address1'];
    $Address2 = $_POST['address2'];
    $Address3 = $_POST['address3'];
    $City     = $_POST['city'];
    $State    = $_POST['state'];
    $Postal   = $_POST['postal'];
    $Province = $_POST['province'];
    $Gender   = $_POST['gender'];
    $Phone    = $_POST['phone'];
    $DialCode = $_POST['dial'];
    $Altphone = $_POST['altphone'];
    $Service  = $_POST['service'];
    $Email    = $_POST['email'];
    $Comment  = $_POST['comment'];

    $host ="localhost";
    $dbusername = "root";
    $dbpassword = "";
    $dbname = "vici";

    $conn = new mysqli($host,$dbusername,$dbpassword,$dbname);


    if (mysqli_connect_error())
    {
        echo "Failed to connect to MySQL:".mysqli_connect_error();
    }
    else{
        $fet = "SELECT * FROM userdetail ORDER BY Vendor DESC LIMIT 1";
        {
            if ($conn->query($fet))
            {
                $upd = " UPDATE userdetail SET Tittle = '$Title', First = '$First', Middle = '$Middle', Last = '$Last', Address1 = '$Address1', Address2 = '$Address2', Address3 = '$Address3', City = '$City', State = '$State', Postal = '$Postal', Province = '$Province', Gender = '$Gender', Phone = '$Phone', DialCode = '$DialCode', Altphone = '$Altphone', Service = '$Service', Email = '$Email', Comment = '$Comment' 
                WHERE SN = $fet ";

                if ($conn->query($upd))
                {
                    echo "Record will update";
                    echo "<script> window.location.assign('Userdataretrive.php'); </script>";
                }
                else {
                    {
                        echo "Updating Error !!! " .$conn->error; 
                    }
                }
            }
            $conn->close();
        }
    }  
?>
  

更新错误!!!您的SQL语法有误;检查   对应于您的MariaDB服务器版本的手册   'SELECT * FROM userdetail ORDER BY供应商DESC附近使用的语法   第2行的LIMIT 1'

1 个答案:

答案 0 :(得分:0)

子查询需要括号周围。

WHERE SN = $fet ";

可以更改为

WHERE SN = ( $fet )";