Jump to content

Archived

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

RSprinkel

Error

Recommended Posts

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.

[code]<?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';
?>
[/code]

Share this post


Link to post
Share on other sites
Avoid using [b]reserved words[/b] as table names or field names. Here's a list of what not to use:

http://dev.mysql.com/doc/refman/5.0/en/reserved-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:

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

Share this post


Link to post
Share on other sites
[quote author=Guardian2006 link=topic=108398.msg436531#msg436531 date=1158589460]
Your error message also indicates you have to single quotes together -
[quote]'PA_LowRider'',[/quote]
[/quote]

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.

Share this post


Link to post
Share on other sites
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.

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.