Jump to content

Archived

This topic is now archived and is closed to further replies.

elis

Second set of eyes? INSERT error

Recommended Posts

I keep getting the following error:
[quote]Query send failedYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'by,additional,sentdate,subject) VALUES ('','24,'Envi','','Jalee' at line 1[/quote]

here's the code

[code]
$date = date('Y-m-d');
$send = "INSERT INTO report_user (id,ip,reported,rptmessage,by,additional,sentdate,subject) VALUES

('','$ip,'$_POST[reported]','$message','$userpenname','$add','$date','$sub')";
$sent = mysql_query($send) or die("Query send failed".mysql_error());[/code]


I'm not sure what the problem is, I've looked at it a few times and I must be missing something...

Share this post


Link to post
Share on other sites
it's always infront of where it says "near " and then gives that info. so i'm guessing this area:

rptmessage,

maybe its not rptmessage, maybe its misspelled. could be anything almost lol.

Share this post


Link to post
Share on other sites
Try this:

[code]
$date = date('Y-m-d');
$reported = $_POST["reported"];
$send = mysql_query("INSERT INTO report_user (id, ip, reported, rptmessage, by, additional, sentdate, subject) VALUES ('','$ip,'$reported','$message','$userpenname','$add','$date','$sub')") or die("Query send failed ".mysql_error());
[/code]

Share this post


Link to post
Share on other sites
I just tried that, I got the same error again.  :-[

Share this post


Link to post
Share on other sites
Found it:

Try this:


$date = date('Y-m-d');
$reported = $_POST["reported"];
$send = mysql_query("INSERT INTO report_user (id, ip, reported, rptmessage, by, additional, sentdate, subject) VALUES ('','$ip[b]'[/b],'$reported','$message','$userpenname','$add','$date','$sub')") or die("Query send failed ".mysql_error());

Forgot a single quote there :)

Share this post


Link to post
Share on other sites
Same error again :(
I guess I'll have to try again from scratch?

Share this post


Link to post
Share on other sites
Try taking the ID part out? If your ID is autoincremental, you dont have to have that in there, and it may cause an error if you try to alter it.

Share this post


Link to post
Share on other sites
Instead of showing us the code that creates the query, try echoing the query itself.  It's often easier to spot errors when looking at the finished query, without all the extra php syntax.

Share this post


Link to post
Share on other sites
Also, try entering the query through phpMyAdmin; you may have spelled one of your columns incorrectly and it'll catch it.

Share this post


Link to post
Share on other sites
there is nothing wrong with the query, it you COLUMN NAMING

by = reserved word!

I recommend you change that column name, or use backtic operators to enclose it `by`, but that's bad logic, because the MySQL road map states it's going to put more restrictions on reserved words in furtue versions of MySQL!!!

me!

Share this post


Link to post
Share on other sites
^ Ah, the 'by' was the problem as you said. Thank you all for your help. Now, it's finally working correctly.

Share this post


Link to post
Share on other sites

×

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.