...

View Full Version : SQL Syntax Error



dniwebdesign
10-16-2004, 09:14 AM
Why would this give me the error below. I think I have everything right...



$sql=mysql_query("INSERT INTO scripts_registered (serial,to,email,website,script,releasetype) VALUES ('".$register["serial"]."','".$register["to"]."','".$register["email"]."','".$register["website"]."','".$register["script"]."','".$register["releasetype"]."')") or $e=mysql_error();


Here's the error:

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 'to,email,website,script,releasetype) VALUES ('1-BFREE-758','Daw

raf
10-16-2004, 10:04 AM
'to' is a reserved word

http://dev.mysql.com/doc/mysql/en/Reserved_words.html

kliqster
10-17-2004, 12:30 AM
Try:


$sql = mysql_query("INSERT INTO `scripts_registered`
(`serial`, `to`, `email`, `website`, `script`, `releasetype`)
VALUES('{$register['serial']}',
'{$register['to']}',
'{$register['email']}',
'{$register['website']}',
'{$register['script']}',
'{$register['releasetype']}')") or $e = mysql_error();

Fou-Lu
10-17-2004, 12:21 PM
Cough...


'to' is a reserved word

http://dev.mysql.com/doc/mysql/en/Reserved_words.html

marek_mar
10-17-2004, 12:50 PM
It's backticked in that code sample.

trib4lmaniac
10-17-2004, 01:45 PM
It's backticked in that code sample.
In case anyone's wondering, that allows you to use reserved words as identifiers.

kliqster
10-17-2004, 03:15 PM
Cough...

I use `to` myself. :)

Fou-Lu
10-17-2004, 07:07 PM
I use `to` myself. :)

Lol, pardon me. Perhaps I should pay closer attention to the quotation... to realizes its not really quotation.

raf
10-17-2004, 08:02 PM
This is starting to sound like some of the endless wining at the Old Coders Neetings :D (How do i know :eek: ).

Backticks are fine, but it makes more sense and makes your code more portable, to simply not use reserved words... Just save other coders (that might work on your db later) some frustrating hours trying to figure out why they keep getting errors, and choose another column-names like 'mail_to', 'mail_message' etc

dniwebdesign
10-17-2004, 10:23 PM
Well the script was for myself but I changed "to" to something else... now it works. Thanks.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum