AMG AMG - 1 year ago 99
PHP Question

PHP SQL WHERE statement with 2 conditions issue

Good day, I'm not really familiar with PHP and i get this error when i try to execute my query.

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result,
boolean given in C:\xampp\htdocs\LoginWithMySQLi\products.php on line

Here's my query:

'SELECT * FROM users WHERE name = '.$name.' AND usertype = premium';

Do you know what i do wrong?

Thanks in Advance

Answer Source

Your query is not working because you are using string values without quotes:

You can use double quotes for string values as:

$sql = 'SELECT * FROM users WHERE name = "'.$name.'" AND usertype = "premium"';

Site note:

This is good to see you are using mysqli_* extension, but suggest to use prepared statement this will protect your code for SQL INJECTION, in PDO you can also use PDO Quote function.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download