我有错误SQLSRV:','附近的语法不正确

时间:2016-12-20 10:13:58

标签: php sqlsrv

  

SQLSTATE:42000代码:102消息:[Microsoft] [用于SQL的ODBC驱动程序11   服务器] [SQL Server]','附近的语法不正确。

我的代码,我用PHP连接sqlsrv:

if(isset($_POST['smlogin']))
{
    $namef = $_POST['fulname'];
    $user = $_POST['emailz'];
    $pass = $_POST['pswz'];
    $md5pass = md5($pass);
    $chondl = "select * from Accounts WHERE email={$user} , MD5Password={$pass}";
    $nhap = sqlsrv_query($conn, $chondl);
    if($nhap)
    {
        echo'<script>alert("Done!"); </script>';
    }
    else
         if( ($errors = sqlsrv_errors() ) != null) {
        foreach( $errors as $error ) {
            echo "SQLSTATE: ".$error[ 'SQLSTATE']."<br />";
            echo "code: ".$error[ 'code']."<br />";
            echo "message: ".$error[ 'message']."<br />";
        }
    }
    }

请帮助:)

1 个答案:

答案 0 :(得分:2)

您需要在查询中替换以下内容

$chondl = "select * from Accounts WHERE email={$user} , MD5Password={$pass}";

替换后

$chondl = "select * from Accounts WHERE email='$user' AND MD5Password='$pass'";