Mysql_Fetch_Array() Expects Parameter 1 to Be Resource Problem

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.

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in...' but my query is correct

$query = "SELECT * FROM newuser WHERE token='$token'";
$result = mysql_query($query) or die(mysql_error());

while($row=mysql_fetch_array($result)) {
do stuff...
}

If the die statement is not executed, $result is OK when you enter the while loop. The problem then is probably that you use $result for a query inside the loop as well, eventually leading to it being set to false.

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in

Your query ($myQuery) is failing and therefore not producing a query resource, but instead producing FALSE.

To reveal what your dynamically generated query looks like and reveal the errors, try this:

$result2 = mysql_query($myQuery) or die($myQuery."<br/><br/>".mysql_error());

The error message will guide you to the solution, which from your comment below is related to using ORDER BY on a field that doesn't exist in the table you're SELECTing from.

Unexpected Warning - mysql_fetch_array() expects parameter 1 to be resource, boolean given

Given that your while loop "runs once, even though there are 3 results", I'm going to take a shot in the dark and say that you are using $result in the loop contents by mistake.

Warning: mysql_fetch_array() expects parameter 1 to be resource, null given.

first try to check the data of $q

and after that try with this query:

mysql_query("SELECT * FROM `ajax_demo` 
WHERE id = '" . mysql_real_escape_string($q) ."'");


Related Topics



Leave a reply



Submit