Why does php show error for my SQL query
- by ZincX
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.