Warning: MySQL_Fetch_Array() Expects Parameter 1 to Be Resource, Boolean Given In

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.

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.

SQL Server DateTime conversion failure

Place the CASE and ISDATE inside the CONVERT() function.

SELECT COUNT(*) FROM MyTable
WHERE
DATEDIFF(dd, CONVERT(DATETIME, CASE IsDate(lastUpdate)
WHEN 1 THEN lastUpdate
ELSE '12-30-1899'
END), GetDate()) < 31

Replace '12-30-1899' with the default date of your choice.

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'];
}

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\pyrll\index.php on line 58

It's possible that:

  1. You don't have an active database connection

  2. The query result does not yield anything (ie the response is NULL) or

  3. There is a syntax error in your query

I would use a program like Toad (Windows) or Sequel Pro (Mac OS) or good ol' terminal to check that your query yields a result.

If you are using something like a sprintf() to assemble your query from variable, ensure that you are getting the proper string output with an echo.

mysql_connect("localhost", "mysql_user", "mysql_password") or

die("Could not connect: " . mysql_error());

mysql_select_db("mydb");

$result = mysql_query("SELECT id, name FROM mytable");

Check that the query string (SELECT id, name FROM mytable) works externally

eg. echo $query = sprintf("SELECT id, name FROM mytable WHERE id = %d",$var);

if echo $query yields something like:

[GOOD]: SELECT id, name FROM mytable WHERE id = 5

else

[BAD]: SELECT id, name FROM mytable WHERE id = 

If the outputs well, then the rest should work just fine. Unless of course you don't have access to a database.

while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
printf("ID: %s Name: %s", $row[0], $row[1]);

}

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

This is not correct

'SELECT users_email, users_pass FROM users WHERE users_email = $email'

better way is

"SELECT users_email, users_pass FROM users WHERE users_email = '$email'"

Need to wrap the string data in single quote.

The POST data is directly being used in the query which is not good. Start using PDO prepared statements to avoid sql injections or at-least sanitize data as

$email = $_POST['users_email'];
$pass = $_POST['users_pass'];
$con = mysql_connect('localhost','root','');
// Make sure we connected succesfully
if(! $con)
{
die('Connection Failed'.mysql_error());
}

$email = mysql_real_escape_string($email);


Related Topics



Leave a reply



Submit