"Warning: MySQL_Fetch_Array() Expects Parameter 1 to Be Resource, Boolean Given" Error While Trying to Create a PHP Shopping Cart

mysql_fetch_array() expects parameter 1 to be resource problem

You are not doing error checking after the call to mysql_query:

$result = mysql_query("SELECT * FROM student WHERE IDNO=".$_GET['id']);
if (!$result) { // add this check.
die('Invalid query: ' . mysql_error());
}

In case mysql_query fails, it returns false, a boolean value. When you pass this to mysql_fetch_array function (which expects a mysql result object) we get this error.

mysql_fetch_array() expects parameter 1 to be resource

You're not running the query, it's only being stored in a string called $result. Here is the function you need: http://php.net/mysql_query

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, object given in

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.

Read the doc here: http://php.net/manual/en/mysqli-result.fetch-array.php

To fix this, execute the query first, then store the result to a variable then later fetch that variable.

$sql = "select * from privinsi";
$result = mysqli_query($connection,$sql);
while($r = mysqli_fetch_array($result))
{
// your code here
}

mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows etc... expects parameter 1 to be resource

A query may fail for various reasons in which case both the mysql_* and the mysqli extension will return false from their respective query functions/methods. You need to test for that error condition and handle it accordingly.

mysql_ extension:

NOTE The mysql_ functions are deprecated and have been removed in php version 7.

Check $result before passing it to mysql_fetch_array. You'll find that it's false because the query failed. See the [mysql_query][1] documentation for possible return values and suggestions for how to deal with them.

$username = mysql_real_escape_string($_POST['username']);
$password = $_POST['password'];
$result = mysql_query("SELECT * FROM Users WHERE UserName LIKE '$username'");

if($result === FALSE) {
trigger_error(mysql_error(), E_USER_ERROR);
}

while($row = mysql_fetch_array($result))
{
echo $row['FirstName'];
}


Related Topics



Leave a reply



Submit