I have error SQLSRV : Incorrect syntax near ','

6.1k views Asked by At

SQLSTATE: 42000 code: 102 message: [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Incorrect syntax near ','.

My code , i use PHP to connect 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 />";
        }
    }
    }

Please, help :)

1

There are 1 answers

0
Ankur Tiwari On BEST ANSWER

You need to replace following thing in your query

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

After Replacement

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