Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

SQL Warnings in my PHP code

$
0
0

Hi everybody,

 

Please can someone check the snippet of code below and say why it generates a warning as "Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in functions.php on line 6". 
 
Same warning is generated for the next line i.e. line 7. Ofcourse this is only due to the earlier line i.e. line 6.
 
1. $con =  mysqli_connect($db_host, $db_user, $db_pass, $db);
2.        if(mysqli_connect_errno($con)) die('Could not connect: '. mysqli_connect_error());
3.
4.        $query = "Select * FROM $table WHERE username = '$user' AND id = $id "; // AND id = '$id' AND
5.        $result=mysqli_query($con, $query);
6.        $row = mysqli_fetch_array($result,MYSQLI_ASSOC);
7.        mysqli_free_result($result);

I have checked the usage of mysqli_fetch_array($result,MYSQLI_ASSOC) on google and it seems to be almost the same.

 

The difference was only in the $query which on w3schools examples was as follows

 

$query ="SELECT Lastname,Age FROM Persons ORDER BY Lastname";

 

Can someone please help. Thanks all

 

 

 


Viewing all articles
Browse latest Browse all 13200

Trending Articles