I am trying to set $nextPageID and $nextPageTitle with the following code. Unfortunately they are not getting set.
$pageCategoryID = 1;
$nextPageOrder = 2;
$fetchedNextPageData = mysql_query("
SELECT pageID, pageCategoryID, 'order', title
FROM pages
WHERE pageCategoryID='$pageCategoryID' AND 'order'='$nextPageOrder'
") or die(mysql_error());
while ($nextPageArray = mysql_fetch_array($fetchedNextPageData)) {
$nextPageID = $nextPageArray['pageID'];
$nextPageTitle = $nextPageArray['title'];
}
My table pages contains a row with pageID = 2, pageCategoryID = 1, order = 2, title = Next Page, plus 4 other columns with data I don’t need for this query.
This code has been simplified for testing purposes. It will be sanitized after I get it working.
Any thoughts on what I can do to get this bit of code working?
Forget about PHP right now. This is your SQL query:
In SQL, as in many other languages, you use quotes to type literal strings. Since the
'order'string will never equal the'1‘ string, your query will always return zero rows, no matter the other values.If
orderis a column name, you cannot single-quote it.Now, given that
ORDERis a reserved word, you’ll have to use backticks around it. You can also type integers as integers (there’s no need to quote them):