Jump to content

[SOLVED] What is wrong with this?


SJames

Recommended Posts

try this one

<?php
$q = "Insert into `messages` (sender, reciever, date, read, subject, message) Values('".$sender."', '".$reciever."', '".$date."', 'no', '".$subject."', '".$message."')";
mysql_query($q) or die(mysql_error()."<br />".$q;
?>

 

And if it errors paste the exact error in.

Like I said, same error as before:

 

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 'read, subject, message) Values('test1', 'test2', '1193537533', 'no', 'test', 'test')' at line 1
Insert into `messages` (sender, reciever, date, read, subject, message) Values('test1', 'test2', ''1193537533, 'no', 'test', 'test')

well you obviously did not use what I said

<?php<?php
$q = "Insert into `messages` (sender, reciever, date, read, subject, message) Values('".$sender."', '".$reciever."', '".$date."', 'no', '".$subject."', '".$message."')";
mysql_query($q) or die(mysql_error()."<br />".$q);
?>

as it would echo out the sql error a break line and the query

and I think inevertinently I have found your problem.  Certain words are "special" in mysql like id, you must quote them.  I believe read is one of these, so try what I gave you see if it errors, if it does quote out the field names and see what happens.

read is not but date is. Also, you need a space after VALUES. Try...

 

<?php

$sql = "INSERT INTO messages (
           sender, reciever, `date`, read, subject, message
         ) VALUES (
           '$sender', '$reciever', '$date', 'no', '$subject', '$message'
         );";

if (mysql_query($sql)) {
 echo "success";
} else {
 echo mysql_error() . "<br />$sql";
}

?>

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.