Jump to content


Photo

Error


  • Please log in to reply
5 replies to this topic

#1 RSprinkel

RSprinkel
  • Members
  • PipPipPip
  • Advanced Member
  • 69 posts

Posted 17 September 2006 - 03:32 PM

Hi all,

I am getting this error when I try to enter data into a database via a form.

Here is the error:

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 'mod, track) VALUES('PA_LowRider'','09/14/2006','Cup','Cup','Richmond')' at line 1

Here is the code trying to process the data into the database.

<?php

include 'db.php';

$sierra = $_POST['sierra'];
$date = $_POST['date'];
$series = $_POST['series'];
$mod = $_POST['mod'];
$track = $_POST['track'];

$sierra = stripslashes($sierra);
$date = stripslashes($date);
$series = stripslashes($series);
$mod = stripslashes($mod);
$track = stripslashes($track);
	

//insert info into win table
$sql = mysql_query ("INSERT INTO win (sierra, date, series, mod, track)
VALUES('$sierra','$date','$series','$mod','$track')") or die (mysql_error());
if(!$sql){
	echo 'There has been an error processing this win. Please contact the webmaster.';
}

mysql_close($connection);

//show user decision page
include 'win_filed.php';
?>

RSprinkel
A PHP/MySQL NOVICE I AM

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 17 September 2006 - 03:42 PM

Avoid using reserved words as table names or field names. Here's a list of what not to use:

http://dev.mysql.com...rved-words.html

The best solution would be to rename 'mod' to 'xmod' or something.  The sloppy workaround is to use backticks on reserved words like `mod`

While debugging, it never hurts to echo the query as well as the error, thus:

$query = " ... whatever it is ...";
$result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);// gotcha!

Legend has it that reading the manual never killed anyone.
My site

#3 RSprinkel

RSprinkel
  • Members
  • PipPipPip
  • Advanced Member
  • 69 posts

Posted 17 September 2006 - 05:33 PM

Thanks for the info.
RSprinkel
A PHP/MySQL NOVICE I AM

#4 Guardian2006

Guardian2006
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 18 September 2006 - 02:24 PM

Your error message also indicates you have to single quotes together -

'PA_LowRider'',



#5 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 18 September 2006 - 02:57 PM

Your error message also indicates you have to single quotes together -

'PA_LowRider'',


There's an interesting observation.  I suspect the first of those trailing single quotes actually came with the posted information and was originally escaped (and would have gone into the database OK) but the stripslashes removed the escaping and rendered it back as ' which caused the mistake.  Skip stripslashes.
Legend has it that reading the manual never killed anyone.
My site

#6 RSprinkel

RSprinkel
  • Members
  • PipPipPip
  • Advanced Member
  • 69 posts

Posted 18 September 2006 - 10:23 PM

Thanks for all the help guys.  I got all those little nasty bugs worked out.  Now I am gonna try to do some sorting or something and hope I don't mess this all up after all of this, LOL.

Again Thanks for the Help and I am sure I will have some more questions regarding some other help on soon.


RSprinkel
A PHP/MySQL NOVICE I AM




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users