Jump to content

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


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
}

Edited by Andy123
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.