here is the new updated code, i have also included the table structure
<?php
include("conn.php");
mysql_select_db("lms") or die(mysql_error());
#===========================================================
# check if username/password has been entered
#===========================================================
if(isset($_POST['login']))
{
if(!$_POST['username'] || !$_POST['password']) { die('enter both fields'); }
#===========================================================
# check if the table contains anything
#===========================================================
$checkdata = mysql_query("select * from users") or die(mysql_error());
if(mysql_num_rows($checkdata) <= 0) { die('no data exists in the database, you need to add a user <a href="admin.php">click here</a>'); }
#===========================================================
# check if user exists in the database
#===========================================================
$username = $_POST['username'];
$checkuser= mysql_query("select username from users where username = '$checkexist'") or die(mysql_error());
if(mysql_num_rows($checkuser) == 0) { die('that username doesnt exist in our database'); }
else{
#===================
$password = md5($_POST['password']);
$query = mysql_query("select password from users");
while($row = mysql_fetch_array($query)) {
#===========================================================
# check if password matches the username
#===========================================================
if ( md5($_POST['password']) != $row['password'] )
{
}
else
{ echo "<script>alert('your in');</script>"; }
}
}
}
else {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" >
<p>Username: </p>
<p><input type="text" name="username" />
<br />
<br />
</p>
<p>Password: </p>
<p><input type="password" name="password" />
<br />
<br />
<input type="submit" value=" login " name="login" />
</p>
</form>
</body>
</html>
<?php } ?>
table structure and its data
CREATE TABLE `users` (
`id` int,
`fname` varchar(20) CHARACTER SET `latin1` COLLATE `latin1_swedish_ci`,
`lname` varchar(20) CHARACTER SET `latin1` COLLATE `latin1_swedish_ci`,
`username` varchar(20) CHARACTER SET `latin1` COLLATE `latin1_swedish_ci`,
`password` varchar(50) CHARACTER SET `latin1` COLLATE `latin1_swedish_ci`,
`level` varchar(10) CHARACTER SET `latin1` COLLATE `latin1_swedish_ci`
);
INSERT INTO `users` (`id`, `fname`, `lname`, `username`, `password`, `level`) VALUES (12, 'myname', 'mylastname', 'sarmenhb', '79ef12f7caa49f3c95499143dc9daf68', 'student');
COMMIT;
this is the alert im receiving. the username doesnt exist in our database