Jump to content


Photo

Second set of eyes? INSERT error


  • Please log in to reply
10 replies to this topic

#1 elis

elis
  • Members
  • PipPipPip
  • Advanced Member
  • 149 posts

Posted 04 October 2006 - 09:19 PM

I keep getting the following error:

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


here's the 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());


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

#2 Jocka

Jocka
  • Members
  • PipPipPip
  • Advanced Member
  • 344 posts
  • LocationDallas, Texas

Posted 04 October 2006 - 09:21 PM

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.

#3 tleisher

tleisher
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts

Posted 04 October 2006 - 09:24 PM

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,'$reported','$message','$userpenname','$add','$date','$sub')") or die("Query send failed ".mysql_error());


#4 elis

elis
  • Members
  • PipPipPip
  • Advanced Member
  • 149 posts

Posted 04 October 2006 - 09:29 PM

I just tried that, I got the same error again.  :-[

#5 tleisher

tleisher
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts

Posted 04 October 2006 - 09:32 PM

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','$reported','$message','$userpenname','$add','$date','$sub')") or die("Query send failed ".mysql_error());

Forgot a single quote there :)

#6 elis

elis
  • Members
  • PipPipPip
  • Advanced Member
  • 149 posts

Posted 04 October 2006 - 09:37 PM

Same error again :(
I guess I'll have to try again from scratch?

#7 tleisher

tleisher
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts

Posted 04 October 2006 - 10:00 PM

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.

#8 roopurt18

roopurt18
  • Staff Alumni
  • Advanced Member
  • 3,749 posts
  • LocationCalifornia, southern

Posted 04 October 2006 - 10:53 PM

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.
PHP Forms : Part I | Part II

JavaScript: Singleton

http://www.rbredlau.com

#9 roopurt18

roopurt18
  • Staff Alumni
  • Advanced Member
  • 3,749 posts
  • LocationCalifornia, southern

Posted 04 October 2006 - 10:55 PM

Also, try entering the query through phpMyAdmin; you may have spelled one of your columns incorrectly and it'll catch it.
PHP Forms : Part I | Part II

JavaScript: Singleton

http://www.rbredlau.com

#10 printf

printf
  • Staff Alumni
  • Advanced Member
  • 889 posts

Posted 04 October 2006 - 11:02 PM

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!



#11 elis

elis
  • Members
  • PipPipPip
  • Advanced Member
  • 149 posts

Posted 05 October 2006 - 02:33 PM

^ Ah, the 'by' was the problem as you said. Thank you all for your help. Now, it's finally working correctly.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users