Forum Moderators: coopster

Message Too Old, No Replies

MySQL insert

         

MartinWeb

10:05 pm on Oct 28, 2009 (gmt 0)

10+ Year Member



I am recieving error messages with this code that tells me to check my MySQL syntax. Does anyone notice anything wrong?

$q2 = "insert into mail(from, to, subject, body, tStatus, fStatus, sent) VALUES ('$member', '$to, '$subject', '$body', '$one', '$one', now());";
$rs = mysql_query($q2) or die ("Could not execute query : $q2." . mysql_error());

TheMadScientist

11:18 pm on Oct 28, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



At a glance there's a missing ' in yours after $to:

$q2 = "INSERT INTO mail (from, to, subject, body, tStatus, fStatus, sent) VALUES ('$member', '$to', '$subject', '$body', '$one', '$one', now());";

MartinWeb

1:02 am on Oct 29, 2009 (gmt 0)

10+ Year Member



Oops, sorry I copied the code wrong. (Well, I deleted the ' when I was writing it.)

Here is the error code I am getting:

Could not execute query : insert into chess_mail (from, to, subject, body, tStatus, fStatus, sent) VALUES ('Joe', 'Fred', 'Hello', 'How are you', '1', '1', now());. 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 'from, to, subject, body, tStatus, fStatus, sent) VALUES ('Joe', 'Fred', 'Hel' at line 1

TheMadScientist

1:36 am on Oct 29, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Didn't even think about it... to is a reserved word:
[dev.mysql.com...]

I'd try changing the col name and going from there.

I usually use something like:
toName forName, etc.

[edited by: TheMadScientist at 1:39 am (utc) on Oct. 29, 2009]

bkeep

1:38 am on Oct 29, 2009 (gmt 0)

10+ Year Member



FROM is a reserved keyword that may be doing it.
Maybe try using backticks `from`
[dev.mysql.com...]

MartinWeb

11:13 am on Oct 29, 2009 (gmt 0)

10+ Year Member



Great, it worked. Thanks!