I am having problems with this script. When I login correctly it says invalid username or password when it shoud say i have successfully logged in as $user
here is the script
PHP Code:
<?php session_start(); include "./global.php";
echo "<title>Login</title>"; if($_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($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 succsessfully logged in as " . $user; //THIS DOES NOT WORK } else { echo "Username and/or password are not valid!"; //THIS IS TAKING ITS PLACE! } } else { echo "The username you supplied does not exist!"; } } else { echo "Complete the form!"; } }