<?php
if (isset($_SESSION['uid']) && $_SESSION['uid']) {
echo "You are already logged in, if you wish to log out, please <a href=\"./logout.php\">click here</a>!\n";
} else {
if (!$_POST['submit']) {
?>
<table border=0 cellspacing=3 cellpadding=3>
<form method='post' action='login.php'>
<tr><td>Username</td><td><input type='text' name='username'></td></tr>
<tr><td>Password</td><td><input type='password' name='password'></td></tr>
<tr><td colspan=2 align='right'><input type='submit' name='submit' value='Login'></td></tr>
</form></table>
<?php
}else {
$user = $_POST['username'];
$pass = $_POST['password'];
if($user && $pass){
$sql = "SELECT id FROM `users` WHERE `username`='".$user."'";
$res = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($res) > 0){
$sql2 = "SELECT id FROM `users` WHERE `username`='".$user."' AND `password`='".md5($pass)."'";
$res2 = mysql_query($sql2) or die(mysql_error());
if(mysql_num_rows($res2) > 0){
$row = mysql_fetch_assoc($res2);
$_SESSION['uid'] = $row['id'];
echo "You have successfully logged in as " . $user . "<br><br><a href=\"./index.php\">Proceed to the Forum Index</a>\n";
}else {
echo "Username and password combination are incorrect!\n";
}
}else {
echo "The username you supplied does not exist!\n";
}
}else {
echo "You must supply both the username and password field!\n";
}
}
}
?>
i have an error on line 8 "undefined index"...I try to use this $submit = $_POST; but there's a complicate between line 19 and 18....