Instead of $row = mysql_fetch_array($result) use, while($row = mysql_fetch_array($result)) {
ANDecho "Thanks for logging in.";
header("http://www.google.com"); will give you an error because you can't output anything before header function. Either echo a message or redirect the user. :)
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
When the user types username and password, why not check if that exists in the table, rather than get all records and then check ?
$name=$_POST['username'];
$password=$_POST['password'];
Ie., $query = "select * from user where username='$name' and password='$password'";
Then check if this returns more than 1 row. If it does, then the username and password is valid. Else, invalid username and pass.
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
It displays thrice because its looping three times. You can do it this way.
<?php
mysql_connect("localhost", "root", "1234") or die(mysql_error());
mysql_select_db("userlist") or die(mysql_error());
$name=$_POST['name'];
$password=$_POST['password'];
$query = "SELECT * FROM user where username='$name' && password='$password'";
$result = mysql_query($query) or die(mysql_error());
if(mysql_num_rows($result) > 0){
echo "Success!";
}
else
{
echo "Sorry! Wrong name!!";
}
?>
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
you can do the same thing by putting echo :)
echo "success!";
echo "<meta http-equiv=\"refresh\" content=\"2;url=redirectpage.php\">";
This will redirect the script to redirectpage.php after 2 seconds.
More about meta refresh/redirect here.
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356