0

I keep getting this error: Undefined index: username on line 16 Notice: Undefined index: password on line 17 Table 'john.Users' doesn't exist

$username = mysql_real_escape_string($_POST['username']);
$password = $_POST['password'];
$result = mysql_query("SELECT * FROM Users WHERE UserName LIKE '$username'");

if($result === FALSE) {
    die(mysql_error());  
}
Cerbrus
  • 65,559
  • 18
  • 128
  • 140

3 Answers3

0

first write var_dump($_POST); and see whether ur username and password is set or not if it is not check ur html form tag method attribute value is POST or not. like this
<form method="post">

other case in sql check database have users table
also check whether is that Users or users ...(mysql case sensetive)

0

looks like $_POST['username'] is not set or empty so use isset() or empty() to avoid php notices or check values like :-

$username = (!empty($_POST['username']) ? $_POST['username'] : '');
$username = mysql_real_escape_string($username);
$password = (!empty($_POST['password']) ? $_POST['password'] : '');

or use check

if(empty($_POST['username']))
 echo 'username is empty';
Rakesh Sharma
  • 13,570
  • 4
  • 35
  • 42
0

Possible problems:

It isn't a POST but a GET request (Check the method attribute of your<form>. Does it say post or get?)

Typo in the name attribute of your <input> element

And as for the other error (Table 'john.Users' doesn't exist): check your mysql database, maybe it's users instead of Users?

giorgio
  • 9,885
  • 2
  • 27
  • 41