1.

Solve : MySql syntax error??

Answer»

Heres the code:

Code: [SELECT]$query = mysql_query("INSERT INTO inbox (to, from, id, sent, read, title, contents) VALUES ('$to', '$from', '$id', '$sent', 'false', '$sub', '$txt')");

Heres the error:

Code: [Select]SQL query:

INSERT INTO inbox(
TO ,
FROM , id, sent,
READ , title, contents )
VALUES (

'to', 'from', 'id', 'senfdt', 'false', 'Lol', 'Hi'
)

MySQL said: 

#1064 - 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, from, id, sent, read, title, contents) VALUES ('to', 'from', 'id', 'senfdt',' at line 1
Have you made sure all the table fields exist?
Have you USED the right data-types for the fields?

For example:
Quote

INSERT INTO inbox (to, from, id, sent, read, title, contents) VALUES ('$to', '$from', '$id', '$sent', 'false', '$sub', '$txt')
The "read" field - is that a boolean? If so, remove the apostrophes around "false".Na, read is a text. Booleans don't work for me, for some reason. And yes, all the tables exist.

Also, id is a number value. I tried making it $id, but it didn't work.

And, contents is a LONGTEXT. Are the values too big for any of the fields? Ex: if the field for ID is INT(2), and the value $id is 111.Have you tried assigning the variables in the document just to see if it works? Then you would know if it's an error with the insert or getting the variables.Yes, I tried USING php on a page. It didn't do anything. And kpac, its INT(11), and the value is 2I think I realise what's wrong here.

Notice in the SQL error, "to", "from", and "read" are in uppercase. I'm PRESUMING they're reserved keywords?
Try changing the field NAMES to something else.


Discussion

No Comment Found