PDA

View Full Version : MySQL Syntax Error..


Spacetech
01-04-2006, 03:29 AM
When I use this code, I get
MYSQL 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 'replace) VALUES ('','[b]','')' at line 1

The Code is
$code = $_POST['code'];
$replace = $_POST['replace'];

mysql_query("INSERT INTO codes (id,code,replace) VALUES('','$code','$replace')") or die('<br>MYSQL ERROR: ' . mysql_error());

and the table is setup like
CREATE TABLE `codes` (
`id` INT(4) NOT NULL AUTO_INCREMENT ,
`code` VARCHAR(225) NOT NULL ,
`replace` VARCHAR(225) NOT NULL ,
PRIMARY KEY (`id`) );

Please help :confused:

vinyl-junkie
01-04-2006, 04:18 AM
Change this:

mysql_query("INSERT INTO codes (id,code,replace) VALUES('','$code','$replace')") or die('<br>MYSQL ERROR: ' . mysql_error());


to this:

mysql_query("INSERT INTO codes ('id','code','replace') VALUES('','$code','$replace')") or die('<br>MYSQL ERROR: ' . mysql_error());

Kid Charming
01-04-2006, 06:03 AM
For column names, be sure to use backticks instead of single quotes; otherwise, the server thinks you're working with literal strings:


INSERT INTO
codes
(`id`
,`code`
,`replace`)


Ideally, though, you should rename your 'replace' column, as REPLACE is a reserved word, and leave the backticks out.

Spacetech
01-04-2006, 09:57 PM
vinyl-junkie- That didn't work

Kid Charming - That did work

That a lot guys!!

vinyl-junkie
01-05-2006, 02:30 AM
vinyl-junkie- That didn't work
I find that very strange, especially since I created a table in a test database on my server using your CREATE TABLE code, then an identical sql statement to what I posted (except I ran it through phpMyAdmin, but that shouldn't make any difference.) Oh, well.