I am creating a login page with help of php
and mysql
. I am having problem on authenticating when multiple user data stored in database .
Suppose i have table with two user data
s.no username password
1 user1 1234
2 user2 234
when I am giving username and password of first serial no then there is no problem but when i am giving username user1 and password 234 . then user2 is getting authenticated... how to match username and password row wise?? I am providing my backend code.
I tried to print the query result ,it seems its changing username according to password entered.
enter code here
$result = mysqli_query($con,"select * from users where
username='$username' and password ='$password'")
or die("Failed to connect to database".mysql_error());
$row = mysqli_fetch_array($result);
if ($row['username'] == $username && $row['password'] == $password)
{
if($username=='user1')
{
header('Location:htm1/forms.php');
echo "Login successful!!! Welcome ".$row['username'];
}
elseif($username=='user2')
{
header('Location:../php/index.php');
}
else{'
echo"failed";
}
i expect when i enter user1 and password doesn't mach with password of user1 then it should say login failed