0

I am getting this error

Notice: Undefined index: username in C:\xampp\htdocs\login.php on line 24

Notice: Undefined index: password in C:\xampp\htdocs\login.php on line 25

on this code

<?php

session_start();

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

if ($username&&$password)
{

$connect = mysql_connect("localhost","root","") or die ("couldn't connect");
mysql_select_db("test") or die ("couldn't find DB");

$query = mysql_query("select * FROM users WHERE username='$username'");

$numrows = mysql_num_rows($query);

if($numrows!=0)
{
//login goahead

while ($row = mysql_fetch_assoc($query))
{
   $dbusername = $row['username'];
   $dbpassword = $row['password'];

if($username==$dbusername&&$password==$dbpassword)

{
  echo "You're in! <a href='member.php'>click here to continue</a>";
  $_SESSION['username']=$username;

}
else
   echo"Incorrect Password";

}
}
else
die("That user does not exist!");



}
else
die("please enter a username and password");

?>

I have tried changing around where the if statement that checks DB username and pass that is and tried to redefine the calls but it wont work. any help will be great.

1 Answers1

1

Your problem appears to be here:

$dbusername = $row['username'];
$dbpassword = $row['password'];

Your SQL query seems to suggest that it is not returning any results with the row index username or password.

ie. $row['username'] does not exist etc..

Aidan
  • 757
  • 3
  • 13
  • 1
    HAHA omg thank you for pointing that out.. i forgot to caps it. man that takes me back to highschool days. thanks a ton – user3204744 Jan 17 '14 at 01:20