I’m having an issue with MySQL and PHP.
When I try to create a user from PHP and add to the database I get the error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ”user’, ‘password’) VALUES(, )’ at line 1
This is my PHP code:
$user = $_REQUEST["user"];
$password = $_REQUEST["pass"];
// Make a MySQL Connection
mysql_connect("localhost", "root", "root") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());
// Insert a row of information into the table "example"
mysql_query("INSERT INTO accounts('user', 'password')
VALUES($user, $password)")
or die(mysql_error());
echo "Data Inserted!";
You need to escape the field names with back-ticks (or nothing), not single-quotes, and presumably enclose the username and password in single-quotes.: