1

Error while inserting name and password using a form to sql server using php. Can anyone help me?

$name = $_POST['add_name'];
$password =$_POST['add_pass'];

$query = "INSERT INTO zTest(user, password) VALUES ('".$name."','".$password."');";
$params = array();
$options =  array( "Scrollable" => SQLSRV_CURSOR_KEYSET );
$stmt = sqlsrv_query($conn, $query, $params, $options ); 
if($stmt === false){
die ( print_r (sqlsrv_errors(), true));
}

Error Message:

Array ( [0] => Array ( [0] => 42000 [SQLSTATE] => 42000 [1] => 156 [code] => 156 [2] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near the keyword 'user'. [message] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near the keyword 'user'. ) )

1 Answer 1

1

user is a reserved keyword in Sql-Server. use as square bracket like [user]

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.