Jump to content

Mysql_Fetch_Array() Expects Parameter 1 To Be Resource, Boolean Given In C


d_governor

Recommended Posts

$sql = ("select * from MainAdmin WHERE security = '$username' and password = '$password'");

$Userquery = mysql_query($sql);

$Userfetch = mysql_fetch_array($Userquery);

 

 

if (mysql_num_rows($Userquery)==0 )

 

{

echo "<font color=#ff0000><Center>**Failed Login**</Center></font>";

}

 

if (mysql_num_rows($Userquery) != 0 )

{

$_SESSION['logged_in'] == true;

$_SESSION['Security'] = $Userfetch['Security'];

$_SESSION['Name'] = $Userfetch['Name'];

if($Userfetch['status'] == 'MainAdmin' || 'Admin')

{

$Page = 'adminP.php';

}

Your query is failing, and you are trying to hand $Userquery off to mysql_fetch_array() as a resource. However, mysql_query() returns FALSE on failure, hence why $Userquery is FALSE. That is why you get this warning; you are giving a boolean value where a resource value is expected - exactly as the warning says. You should check if the query was executed successfully, e.g.:

 


$Userquery = mysql_query($sql);

if ($Userquery) {
// Query executed successfully

if (mysql_num_rows($Userquery) > 0) {
// At least one row returned - now we can fetch it/them

while ($row = mysql_fetch_array($Userquery) {
// Do something
}
}

else {
// No rows returned
}
}

else {
// Error executing query
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.