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));

Recommended Answers

All 3 Replies

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...

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'''

Member Avatar

Single quote around $brand may help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.