Jump to content

mysql_fetch_array() expects parameter 1 to be resource, boolean


gelobelmonte

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

Link to comment
Share on other sites

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;

  }

 

 

Link to comment
Share on other sites

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.