This is my login.php page
<!DOCTYPE html>
<html>
<body>
<?php
$f_usr= $_POST["username"];
$f_pswd= $_POST["password"];
$con=mysql_connect("localhost","root","");
if(! $con)
{
die('Connection Failed'.mysql_error());
}
mysql_select_db("login",$con);
$result=mysql_query("SELECT * FROM data");
while($row=mysql_fetch_array($result))
{
if($row["username"]==$f_usr && $row["password"]==$f_pswd)
{
echo "<script language=\"JavaScript\">\n";
echo "alert('Successfully Log In');\n";
echo "window.location='MainPage.html'";
echo "</script>";
}
else
{
echo "<script language=\"JavaScript\">\n";
echo "alert('Username or Password was incorrect!');\n";
echo "window.location='login.html'";
echo "</script>";
}
}
?>
</body>
</html>
This is my register.php page
<?php
$connect=mysqli_connect('localhost','root','','login');
if(mysqli_connect_errno($connect))
{
echo 'Failed to connect';
}
?>
<?php
// create a variable
$username=$_POST['username'];
$password=$_POST['password'];
//Execute the query
mysqli_query($connect,"INSERT INTO data(username, password)
VALUES('$username','$password')");
if(mysqli_affected_rows($connect) > 0)
{
echo "<script language=\"JavaScript\">\n";
echo "alert('Successfully Register');\n";
echo "window.location='MainPage.html'";
echo "</script>";
}
else
{
echo "<script language=\"JavaScript\">\n";
echo "alert('Failed to Register');\n";
echo "window.location='Register.html'";
echo "</script>";
}
?>
Here's my problem. I using xammp and I have 3 data currently iin my database. Wheni try to log in with my first data in databse it works, but when i try to log in with the 2nd data in databse it show incorrect username and password? Why?