[HELP] PHP Error!

Status
Not open for further replies.

Kryptos

prjRev.com
Jul 21, 2010
2,205
1,252
For the past few hours I have been following a tutorial on how to make a login system.
I'm done now, but it seems there's a problem with line 18 of my login.php.
I've checked if there was any errors, but I couldn't find any.

Here's the code:

PHP:
<?php
session_start();
$username = $_POST['username'];
$password = $_POST['password'];
if ($username && $passsword)
{
$connect = mysql_connect("localhost","root","3") or die("Couldn't connect!!");
mysql_select_db("phplogin") or die("Couldn't find db!");
$query = mysql_query("SELECT * FROM users WHERE username='$username'");
$numrows = mysql_num_rows($query);
if ($numrows!=0)
{
* while (&row = mysql_fetch_assoc($query))
{
$dbusername = $row['username'];
$dbpassword = $row['password'];

}
}
//Check to see if they match!
if ($username==$dbusername&&$password==dbpassword)
{
*echo "You're in! <a href='member.php'>Click</a> here to enter the member page.";
$_SESSION['username]==$username;
}
else
*** echo "Incorrect password!
}
else
die("That user doesn't exist!");
echo $numrows;
}
else
die("Please enter a username and a password");
*
?>
Thats the login.php, if you didn't find any errors, I also have members.php, logout.php and index.php. So please help! ;p

If you need to see the error then just tell me and I'll put up a demo.

Thanks - Kryptos
 

RastaLulz

fight teh power
Staff member
May 3, 2010
3,926
3,921
Well, the code that you provided is horribly disorganized, and there's many mistakes.

I cleaned it up a bit - try this:
PHP:
<?php
session_start(); 
$username = $_POST['username']; 
$password = $_POST['password']; 
if(isset($username) && isset($passsword))  {
  $connect = mysql_connect("localhost","root","3") or die("Couldn't connect!!");
  mysql_select_db("phplogin") or die("Couldn't find db!");
  $query = mysql_query("SELECT * FROM users WHERE username = '{$username}';");
  $numrows = mysql_num_rows($query);
  if($numrows != 0) {
    while($row = mysql_fetch_assoc($query)) {
      $dbusername = $row['username'];
      $dbpassword = $row['password'];
    }
    //Check to see if they match!
    if($username == $dbusername && $password == $dbpassword) {
      echo "You're in! <a href='member.php'>Click</a> here to enter the member page.";
      $_SESSION['username'] = $username;
    }else{
      echo "Incorrect password!";
    }
  }else{
    echo "That user doesn't exist!";
  }
}else{
  echo "Please enter a username and a password";
}
?>
 

Kryptos

prjRev.com
Jul 21, 2010
2,205
1,252
Thanks Rasta, now the error, is gone, but something really weird is happening, it returns "Please enter a username and a password" and I did, I've tried with multiple accounts and different browsers. IE7 and Safari. Should I use Firefox? Because I really can't find what's wrong, the code looks fine.
 

RastaLulz

fight teh power
Staff member
May 3, 2010
3,926
3,921
It doesn't matter what browser you use, as PHP is ran server side, and not client side.

Are you sure that your login form has the correct names assigned?
 

Kryptos

prjRev.com
Jul 21, 2010
2,205
1,252
Yea, I'm pretty sure, here is the code anyways:

PHP:
<html>
<form action='login.php' method='POST'>
Username: <input type='text' name='username'><br>
Password: <input type='password' name='password'><br>
<input type='submit' value='Log in'><br>
</form>
</html>
 

RastaLulz

fight teh power
Staff member
May 3, 2010
3,926
3,921
Yea, I'm pretty sure, here is the code anyways:

PHP:
<html>
<form action='login.php' method='POST'>
Username: <input type='text' name='username'><br>
Password: <input type='password' name='password'><br>
<input type='submit' value='Log in'><br>
</form>
</html>

I see what you did wrong - you spelled password wrong. :p

It's password, not passsword:
PHP:
<?php
session_start(); 
$username = $_POST['username']; 
$password = $_POST['password']; 
if(isset($username) && isset($password))  {
  $connect = mysql_connect("localhost","root","3") or die("Couldn't connect!!");
  mysql_select_db("phplogin") or die("Couldn't find db!");
  $query = mysql_query("SELECT * FROM users WHERE username = '{$username}';");
  $numrows = mysql_num_rows($query);
  if($numrows != 0) {
    while($row = mysql_fetch_assoc($query)) {
      $dbusername = $row['username'];
      $dbpassword = $row['password'];
    }
    //Check to see if they match!
    if($username == $dbusername && $password == $dbpassword) {
      echo "You're in! <a href='member.php'>Click</a> here to enter the member page.";
      $_SESSION['username'] = $username;
    }else{
      echo "Incorrect password!";
    }
  }else{
    echo "That user doesn't exist!";
  }
}else{
  echo "Please enter a username and a password";
}
?>
 
Status
Not open for further replies.

Users who are viewing this thread

Top