0

Whats wrong with this query? For example $brand holds the value 'apple'
Then I get the error 'unknown column 'apple'

Can anyone see the problem?

if(isset($_GET['brand']) ? $_GET['brand'] : 0){
   $brand = (isset($_GET['brand']) ? $_GET['brand'] : 0);
   $sql = mysqli_query($link, "SELECT COUNT(id) FROM products WHERE brand = $brand  AND 
                       status = 1 ORDER BY id DESC")
    OR die(mysqli_error($link));
3
Contributors
3
Replies
21
Views
3 Years
Discussion Span
Last Post by diafol
0

Hi your Count () function may not result in a field name called id which you are trying to order by so you probably need to alias it.select count(id) as id...

0

Still the same!
I added this error reporting to the file

error_reporting(E_ALL); ini_set('display_errors', 1);   mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

The error that gives is:
'Fatal error: Uncaught exception 'mysqli_sql_exception' with message 'Unknown column 'apple' in 'where clause'''

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.