Jump to content


Photo

P2L Simple Messaging System Problem


  • Please log in to reply
1 reply to this topic

#1 Curtis

Curtis

    Young Padawan

  • Members
  • Pip
  • 1 posts

Posted 11 October 2011 - 09:49 AM

I'm using a PM script from here: http://www.pixel2lif...ssaging_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"?

Am I missing something?

Edited by Curtis, 11 October 2011 - 10:04 AM.


#2 Balor

Balor

    PHP Nerd

  • Members
  • Pip
  • 63 posts
  • Gender:Male
  • Location:Germany->Frankfurt
  • Interests:My beautyful girl, my son and webcoding. I'm also very interested in art but I'm not really good at art... it's sad but true ^^

Posted 13 October 2011 - 04:44 AM

Hello Curtis,

try the following SQL statement:
$sql = "INSERT INTO messages (to,from,subject,message,created) VALUES ('$to','$this->userid','$title','".trim($message)."','$created')";

Seems like the quotes are the problem. So 'to,from,subject,message,created' would be a single field instead of 5 fields.

Best Regards,
Chris
  • Miklo likes this




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users