MYSQL driving me insane

Associate
Joined
13 Jan 2007
Posts
2,424
Location
Belfast,Northern Ireland
Basically im getting this error:

arning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\Users\Test\xampp\htdocs\prototype\administrator\new_promotion.php on line 73

This is the offended lines of code, the last being line 73:
$sql = "SELECT * FROM promotions WHERE order='$order'";
$result = mysqli_query($myconnection, $sql);
$count = mysqli_num_rows($result);

I used the following lines to help debug:
var_dump(mysqli_error($myconnection));
var_dump($result);

Which produces:
string(155) "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 'order='5'' at line 1"
bool(false)

I understand and have proved it is returning false, really what I want it to produce is 0 as I have an if condition which checks the value of $count, which is obviously currently null.

My biggest issue with all of this is I have this exact thing running elsewhere with no problems! I copied and pasted it, changed the variables and now somehow it doesnt work for this part of the site!

$sql = "SELECT * FROM songs WHERE position='$newposition'";
$result = mysqli_query($myconnection, $sql);
// Mysql_num_row is counting table row
$count = mysqli_num_rows($result);

Both order and newposition are ints yes, newposition works fine. both get their values the same way from a POST.

Anybody know whats going on :( ? Currently going mental
 
ORDER is a "special word" in MySQL, since you've created a variable effectively known as ORDER I'd try changing the variable name to something else.
 
you can put the reserved word in backticks to make it work I would think:

SELECT * FROM promotions WHERE `order`='$order'
 
Soon as I saw order mentioned I changed it and it worked fine, feel like an utter ****!
 
I did the same thing the other day but with a more obvious one. I called a column "Date".

Belm. The create statement even read "Date DATE", and I didn't spot it.
 
Back
Top Bottom