php – mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given

php – mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given

This happens when your result is not a result (but a false instead).
You should change this line

$sql = SELECT * FROM $usertable WHERE PartNumber = $partid;

to this:

$sql = SELECT * FROM $usertable WHERE PartNumber = $partid;

because the can interprete $variables while cannot.

Works fine with integers (numbers), for strings you need to put the $variable in single quotes, like

$sql = SELECT * FROM $usertable WHERE PartNumber = $partid ;

If you want / have to work with single quotes, then php CAN NOT interprete the variables, you will have to do it like this:

 $sql = SELECT * FROM .$usertable. WHERE string_column = .$string. AND integer_column = .$number.;
mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given

This means that the first parameter you passed is a boolean (true or false).

The first parameter is $result, and it is false because there is a syntax error in the query.

 ... WHERE PartNumber = $partid;

You should never directly include a request variable in a SQL query, else the users are able to inject SQL in your queries. (See SQL injection.)

You should escape the variable:

 ... WHERE PartNumber =  . mysqli_escape_string($conn,$partid) . ;

Or better, use Prepared Statements.

php – mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given

You are single quoting your SQL statement which is making the variables text instead of variables.

$sql = SELECT * 
    FROM $usertable 
    WHERE PartNumber = $partid;

Leave a Reply

Your email address will not be published.