. Advertisement .
..3..
. Advertisement .
..4..
I receive the ”warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in” error when I try to run my code:
My problem is in the while
statement on line 32:
$connection = mysqli_connect($host, $username, $password, $db_name);
$sql = 'SELECT * FROM provinsi';
while ($r = mysqli_fetch_array($connection, $sql)) { // line 32
$id = $r['id'];
}
Can someone give me some solution for the error?
The cause:
mysqli_fetch_array()
‘s 1st parameter must be a result of a query. What you are doing is you are passing the connection (which doesn’t make sense) and the query command itself.Solution: This can be fixed by running the query first, saving the results to a variable, and then fetching the variable.