Jump to content

SQL syntax error


Andrew R

Recommended Posts

Hi

Anybody have any idea why I'm getting a SQL syntax error on this script SQL query?

[code]mysql_query("INSERT INTO messages (to, subject) VALUES ('$to', '$subject')") or die (mysql_error());[/code]

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, subject) VALUES ('Andrew', '456456',)' at line 1

Cheers
Link to comment
https://forums.phpfreaks.com/topic/35681-sql-syntax-error/
Share on other sites

You could try quoting the table names with back ticks (`) as [b]to[/b] is a [url=http://dev.mysql.com/doc/refman/4.1/en/reserved-words.html]reserved word[/url]. :D

[code]<?php
$sql = "INSERT INTO messages (`to`, `subject`) VALUES ('$to', '$subject')";
mysql_query($sql) or die ("Unable to run $sql: " . mysql_error());
?>[/code]

Regards
Huggie
Link to comment
https://forums.phpfreaks.com/topic/35681-sql-syntax-error/#findComment-169039
Share on other sites

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.