and can't get the messages to send.
This is the relevant section of code (from the PHP class), along with the mysql_error() output.
function sendmessage($to,$title,$message) { $to = $this->getuserid($to); //$sql = "INSERT INTO messages SET 'to' = '".$to."', 'from' = '".$this->userid."', 'title' = '".$title."', 'message' = '".trim($message)."', 'created' = NOW()"; $created = time(); $sql = "INSERT INTO messages ('to,from,subject,message,created') VALUES ('$to','$this->userid','$title','".trim($message)."','$created')"; return (@mysql_query($sql)) ? true : false; }
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,subject,message,created') VALUES ('5','1','test','This is a test Messag' at line 1
I have tried the original code (commented out), as well as the subsequent two lines with several variations in quotes. Each one results in this message. The trim() on the second one was also attempted with just '$message', and did not work. The values in the INSERT statement are correct, as far as I can tell. The only potential difference is the integers are actually strings, being put into an INT(11) field on the DB...but I've never had a problem with this before.
I've also tried re-ordering the query to match the order of fields in the database (title,message,to,from,created).
$sql = "INSERT INTO messages (title,message,to,from,created) VALUES ('$title','".trim($message)."','$to','$this->userid','$created')";
This results in the error showing:
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,created) VALUES ('test','This is a test Message','5','1','1318345125')' at line 1
It appears to be a problem with the "to"?
Am I missing something?
Edited by Curtis, 11 October 2011 - 10:04 AM.