This query works:
$con = mysql_connect("localhost","root","pw");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("db", $con);
$sql="INSERT INTO l1_clubmsg (msg, subject, status)
VALUES
(1,1,1)";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con);
But when i change:
$sql="INSERT INTO l1_clubmsg (msg, subject, status)
VALUES
(1,1,1)";
To:
$sql="INSERT INTO l1_clubmsg (msg, subject, status, to)
VALUES
(1,1,1,1)";
I get this error:
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 'to) VALUES (1,1,1,1)' at line 1
The ‘to’ column does exist in l1_clubmsg
Any ideas why this gets an error? thanks
It not because of 4 or more columns that the error is produced.
The error is produced because
tois a keyword and can’t be used like this.You can write the query as:
For the list of keywords you could look here
Note: Normally try to avoid keywords in the query. And if you use make sure that you escape it using backticks(`)