Jump to content

[SOLVED] What is wrong with this?


SJames

Recommended Posts

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

 

mysql_query($sql);

 

 

It responds that there's a syntax error. When I print $sql it comes out correctly.

Link to comment
Share on other sites

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')

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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";
}

?>

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.