Jump to content

MySQL syntax error


cmattoon

Recommended Posts

I'm using a PM script from here: http://www.pixel2life.com/publish/tutorials/608/simple_private_messaging_system/ 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"?

 

I've never had this problem before...am I missing something?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.