Why does php show error for my SQL query

Posted by ZincX on Stack Overflow See other posts from Stack Overflow or by ZincX
Published on 2012-08-26T06:27:32Z Indexed on 2012/08/28 15:38 UTC
Read the original article Hit count: 212

Filed under:
|

UPDATE: My mistake - I made a typo. Nevermind this question.

I'm using php to update a mysql database. The resultant query I'm using when i print it out on my webpage before executing is as follows:

INSERT INTO perch2_content_items
(itemOrder, regionID, pageID, itemRev, itemID, itemJSON, itemSearch ) 
SELECT MAX(itemOrder)+1, 105, 81, 11, 118, 'json', 'search' 
FROM perch2_content_items WHERE regionID=105

When I copy and paste this query directly into the phpmyadmin SQL interface, it works fine. The table gets updated. However, when I try to execute it using my php code as follows, it throws an error.

$insertToPerch = "INSERT INTO perch2_content_items
(itemOrder, regionID, pageID, itemRev, itemID, itemJSON, itemSearch ) 
SELECT MAX(itemOrder)+1, $regionID, $pageID, 
$regionRev, $newItemID, 'json', 'search'
FROM perch2_content_items WHERE regionID=$regionID";
mysql_query(insertToPerch) or die(mysql_error());

The error I'm getting is:

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 'insertToPerch' at line 1

Can anybody help me figure out why it is failing.

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql