[Tool/Web/Other] [PHP] PHP/HTML Masters Help!
#2

1. You cannot use the $row variable outside your loop
2. Why use a loop? If it is only a username, there should only be 1 match, so you can just use
Код:
$row = mysql_fetch_array($query);
I don't know what mysql_fetch_assoc does, but I am going to check that now because I have a test the day after tomorrow (mysql_fetch_assoc looks like mysql_fetch_array.. oh well.)

As for the rest, it looks all OK to me.

I did it like this:
Код:
$query = mysql_query("SELECT * FROM users WHERE username='$_POST[username]'");
if(mysql_num_rows($query) == 0)
{
  // no results
  die('Username not found');
} else {
  $fetch = mysql_fetch_array($query);
  if(md5($_POST['password'] === $fetch['password'])) 
  {
    // a result and log the user in by means of a session
    $_SESSION['username'] == $_POST['username'];
  } else {
    die('Wrong password');
  }
}
Code is only for educational purposes only. It should not be considered as working, even though it most probably will.

-Edit: Ah, so that is mysql_fetch_assoc(); Just looked it up
Reply


Messages In This Thread
[PHP] PHP/HTML Masters Help! - by Ironboy500 - 18.05.2010, 16:06
Re: [PHP] PHP/HTML Masters Help! - by mamorunl - 18.05.2010, 18:41
Re: [PHP] PHP/HTML Masters Help! - by Ironboy500 - 22.05.2010, 09:41
Re: [PHP] PHP/HTML Masters Help! - by Ironboy500 - 23.05.2010, 11:05
Re: [PHP] PHP/HTML Masters Help! - by GTA_Rules - 23.05.2010, 14:45
Re: [PHP] PHP/HTML Masters Help! - by saiberfun - 23.05.2010, 14:56
Re: [PHP] PHP/HTML Masters Help! - by mamorunl - 23.05.2010, 15:07
Re: [PHP] PHP/HTML Masters Help! - by Silent314 - 23.05.2010, 17:36
Re: [PHP] PHP/HTML Masters Help! - by Silent314 - 23.05.2010, 23:38
Re: [PHP] PHP/HTML Masters Help! - by Silent314 - 24.05.2010, 01:57

Forum Jump:


Users browsing this thread: 5 Guest(s)