duane9322 2019-04-06 19:24
浏览 146

如何在PHP中与多个用户进行身份验证?

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

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 下图接收小电路,谁知道原理
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度