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
https://forums.phpfreaks.com/topic/33094-solved-insert-issues/
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
https://forums.phpfreaks.com/topic/33094-solved-insert-issues/#findComment-154198
Share on other sites

When you use an inset dont use SET you use Values...

Replace your code with...

INSERT INTO `messages` ( `id` , `to` , `from` , `subject` , `message` , `recieved` , `read` )
VALUES (
NULL , '1', '1', '$subject', '$message', '$recieved', NULL
);
Link to comment
https://forums.phpfreaks.com/topic/33094-solved-insert-issues/#findComment-154199
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
https://forums.phpfreaks.com/topic/33094-solved-insert-issues/#findComment-154203
Share on other sites

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.