Saturday 6 July 2019

php - SQL syntax error MariaDB server version for the right syntax to use near '@hotmail.com,Employee)' at line 1





I am trying to make a sign up page using php and then when I write the mysql statements below it won't accept it rather it will spit out an error which I am trying to figure out for hours now.



   $query = "INSERT INTO users(username, password,name,surname,email,role)VALUES($username, $password,$name,$lastname,$email,$role)";
$stmt = mysqli_prepare ($dbh, $query) or die(mysqli_error($dbh));


The error that shows is:




You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '@hotmail.com,Employee)' at line 1.




Answer



Make sure you use proper quotes if you insert strings:



$query = "INSERT INTO users(username, password,name,surname,email,role)VALUES('$username', '$password','$name','$lastname','$email','$role')";

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...