Jump to content

mysql_fetch_array() expects parameter 1 to be resource, boolean


Recommended Posts

Good day phpfreaks people! :) i'm a newbie in web programming and I encountered this problem.. I don't know how to fix it.. please help me.. this error prompts everytime i try logging in.. The registration for works but the login doesn't.. please help me.. this is my code where the error is..

 

$db = mysql_connect($mysql_server, $mysql_username, $mysql_password);

  mysql_select_db($mysql_database, $db);

  $sql = "SELECT password, fullname, active FROM ".$mysql_table." WHERE username = '".$_POST['username']."'";

  $result = mysql_query($sql, $db);

  if ($data = mysql_fetch_array($result))

  {

      if ($crypt_pass == $data['password'] && $data['active'] != 0)

      {

        $found = true;

        $fullname = $data['fullname'];

      }

  }

  mysql_close($db);

  if($found == false)

  {

      header('Location: '.$error_page);

      exit;

  }

  else

  {

      session_start();

      $_SESSION['username'] = $_POST['username'];

      $_SESSION['fullname'] = $fullname;

      $rememberme = isset($_POST['rememberme']) ? true : false;

      if ($rememberme)

      {

        setcookie('username', $_POST['username'], time() + 3600*24*30);

        setcookie('password', $_POST['password'], time() + 3600*24*30);

      }

      header('Location: '.$success_page);

      exit;

  }

}

 

Thanks in advance for your help..

 

Gelo

Your query execution is failing and returning a boolean FALSE. Echo mysql_error, along with the query string to see what the error is and what might have caused it.

The examples are quite clear, which part has you stuck? Post the code you tried to use it in and the errors/problems you encountered.

 

I am not sure on how to use it.. but i tried it this way.. this is where the error occurs

 

$db = mysql_connect($mysql_server, $mysql_username, $mysql_password);

  mysql_select_db($mysql_database, $db);

  $sql = "SELECT password, fullname, active FROM ".$mysql_table." WHERE username = '".$_POST['username']."'";

  $result = mysql_query($sql, $db);

  if ($data = mysql_fetch_array($result))

  {

      if ($crypt_pass == $data['password'] && $data['active'] != 0)

      {

        $found = true;

        $fullname = $data['fullname'];

      }

      else die(mysql_error());

  }

  mysql_close($db);

  if($found == false)

  {

      header('Location: '.$error_page);

      exit;

  }

 

 

Additional info:

 

i tried adding this:

 

  $result = mysql_query($sql, $db) or trigger_error ( mysql_error ( ) );

 

but a notice prompted at the error message as follows:

 

Unknown column 'active' in 'field list' in /home/mcssonli/public_html/login.php on line 18

 

 

Well then, there you have it. There is apparently no field named `active` in your table.

 

Wow, I think I'm a bit closer.. I need to make a field on the table named as 'active' then? What would be the suggested parameters? Thank you!

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.