should be simple, SQL query error

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

should be simple, SQL query error

Post by malcolmboston »

i have this MySQL defined in PHP

Code: Select all

$strSQL = "UPDATE competitor
	              SET name = '".$_POST['name']."',
	               website = '".$_POST['website']."',
	          product_page = '".$_POST['product_page']."',
	           price_regex = '".$_POST['price_regex']."',
	                active = '".$_POST['active']."',
	                column = '".$_POST['column']."'
	              WHERE id = '".$_POST['id']."'";
which turns into

Code: Select all

UPDATE competitor SET name = 'Reidys', website = 'http://www.reidys.com', product_page = '/index.pl?submit=View_PLU&PLU=', price_regex = '£(.*)<\\\\/span>', active = 'Y', column = 'C' WHERE id = '6'
but i get the error message

Code: Select all

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 'column = 'C' WHERE id = '6'' at line 7
why?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

column might be a reserved keyword, put backticks around it.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: should be simple, SQL query error

Post by Benjamin »

Code: Select all

$strSQL = "UPDATE `competitor`
	              SET name = '".$_POST['name']."',
	               `website` = '".$_POST['website']."',
	          `product_page` = '".$_POST['product_page']."',
	           `price_regex` = '".$_POST['price_regex']."',
	                `active` = '".$_POST['active']."',
	                `column` = '".$_POST['column']."'
	              WHERE `id` = '".$_POST['id']."'";
Post Reply