How can I get this multi-user login system script to work?
Posted: Wed Mar 14, 2012 1:29 pm
I am working on a multi-user login script where if a username and password number combination (specified in a MySQL database) is entered correctly, then users are to be redirected to the "congrats.php" page. However, with my current code, even with correct username + password input, the script does not work and instead of going to the "congrats.php" page, the login page (loginform2.php) just reloads :/
My coding is:
Any help is appreciated 
My coding is:
Code: Select all
<html><head><title>Multi-User Log In Form</title></head>
<body>
<?php
$self = '';
$name = $_POST['username'];
$pass = $_POST['password'];
?>
<form action = "<?php echo $self; ?>" method = "post">
Username <input type = "text" name = "username" size = "8">
Password <input type = "password" name = "password" size = "8">
<input type = "submit" value="Submit">
</form>
<?php
$conn = mysql_connect("localhost", "root", "") or die ("Err: Conn");
$rs = mysql_select_db("test3", $conn) or die ("Err: Db");
$name = mysql_real_escape_string(trim($name));
$pass = mysql_real_escape_string(trim($pass));
$sql = "select * from users where name='$name' and pass='$pass'";
$rs = mysql_query($sql, $conn);
while ($row = mysql_fetch_array($rs)){
if (mysql_num_rows($rs) >=1)
{
header('Location:congrats.php');
}
else
{
echo "Invalid username and password combination";
}
}
?></body>
</html>