Page 1 of 1

should be simple, SQL query error

Posted: Wed Feb 15, 2006 6:15 am
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?

Posted: Wed Feb 15, 2006 6:22 am
by Benjamin
column might be a reserved keyword, put backticks around it.

Re: should be simple, SQL query error

Posted: Wed Feb 15, 2006 6:22 am
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']."'";