Jump to content

[SOLVED] insert issues


psychohagis

Recommended Posts

Ok I have a page that sends messages, or basically just inserts them into a database.  I am using a sql statement in the the exact same way as to which I've used it before and had it work, except this time it is not working. can anyone help?

[code]
$sql = "INSERT INTO messages SET
to='$to',
from='$from',
subject='$subject',
message='$message',
received='$received'";

if (!@mysql_query($sql))
{
echo '<p>Error sending message' . mysql_error() . '</p>';
}
[/code]

But when I run this I get the following error:
[quote]Error sending message 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='1', from='1', subject='Hello', message='Hello how are
[/quote]

it should continue [b]message='hello how are you',received=[/b] and then insert the variable $received which = time()

Link to comment
Share on other sites


[table]
[tr]
[td][b]Field[/b][/td]
[td][b]Type[/b][/td]
[td][b]Default[/b]      [/td]
[td][b]Extra[/b][/td]
[/tr]
[tr]
[td][u]id[/u][/td]
[td]int(11)[/td]
[td][/td]
[td]auto_increment (primary)[/td]
[/tr]
[tr]
[td]to[/td]
[td]int(11)[/td]
[td]0[/td]
[td][/td]
[/tr]
[tr]
[td]from[/td]
[td]int(11)[/td]
[td]0[/td]
[td][/td]
[/tr]
[tr]
[td]subject[/td]
[td]varchar(50)      [/td]
[td][/td]
[td][/td]
[/tr]
[tr]
[td]message      [/td]
[td]longtext      [/td]
[td][/td]
[td][/td]
[/tr]
[tr]
[td]received[/td]
[td]bigint(20)[/td]
[td]0[/td]
[td][/td]
[/tr]
[tr]
[td]read[/td]
[td]int(11)[/td]
[td]0[/td]
[td][/td]
[/tr]

[/table]
Link to comment
Share on other sites

ok thankyou

id actually use

INSERT INTO `messages` ( `id` , `to` , `from` , `subject` , `message` , `received` , `read` )
VALUES (
NULL , '$to', '$from', '$subject', '$message', '$received', NULL
);

but rather than putting NULL couldnt I just do:

[code]INSERT INTO `messages` (`to` , `from` , `subject` , `message` , `received`)
VALUES (
'$to', '$from', '$subject', '$message', '$received'
);
[/code]
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.