Jump to content

[SOLVED] MySQL INSERT ERROR


kpetsche20

Recommended Posts

Code:

$sql2 = "INSERT INTO mailid (mailid, subject, message, from) VALUES ('".$insert."', '".$subject."', '".$message."', '".$from."')";

 

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 'from) VALUES ('4', 'et', '', 'demouser')' at line 1

Link to comment
https://forums.phpfreaks.com/topic/117144-solved-mysql-insert-error/
Share on other sites

Code:

$sql2 = "INSERT INTO mailid (mailid, subject, message, from) VALUES ('".$insert."', '".$subject."', '".$message."', '".$from."')";

 

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 'from) VALUES ('4', 'et', '', 'demouser')' at line 1

 

What is the value of $insert, $subject, $message and $from ?

Code:

$sql2 = "INSERT INTO mailid (mailid, subject, message, from) VALUES ('".$insert."', '".$subject."', '".$message."', '".$from."')";

 

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 'from) VALUES ('4', 'et', '', 'demouser')' at line 1

 

Hi,

 

from is a reserved word and you need to quote it in backticks if you want to use it as an identifier:

 

`from`

 

Regards,

toivo

just for your information chaps and chapesses, the mysql_error() code you get back tells you exactly where the problem lies, in your case

 

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 'from) VALUES ('4', 'et', '', 'demouser')' at line 1

 

"from" is the problem, and we know this because the syntax error is always the first word after the near ', that is where the fault lies, all the rest of the line of code it gives you is so that you can easily find which word it is failing on.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.