我用 PHP 编写代码,遇到了一些错误,它也跳过了我的 else 语句
<?php
// put your code here
//    $select_query = "Select * from `user_table` where username='$user_username'";
//    $result = mysqli_query($con, $select_query);
    $sql = "Select * from `user_table` where username= ? "; // SQL with parameters
$stmt = $con->prepare($sql); 
$stmt->bind_param("s", $user_username);
$stmt->execute();
$result = $stmt->get_result();
$row_count = mysqli_num_rows($result);
$row_data = mysqli_fetch_assoc($result);
$user_ip = getIPAddress();
if ($_SESSION['attempt'] == 5) {
    $_SESSION['error'] = 'Attempt limit reach';
} else {
         
    if ($row_count > 0) {
        $_SESSION['username'] = $user_username; 
        $row = mysqli_fetch_object($result);
        if (password_verify($user_password, $row_data['user_password'])) {
                
             
//                if ($row_count == 1 and $row_count_cart == 0) {
//
//                    echo"<script>alert('Login Successfully')</script>";
//                    echo"<script>window.open('profile.php','_self')</script>";
//                } else {
//                    $_SESSION['username'] = $user_username;
//                    echo"<script>alert('Login Successfully')</script>";
//                    echo"<script>window.open('payment.php','_self')</script>";
//                }
                if ($row->is_tfa_enabled)
                {
                    $row->is_verified = false;
                    $_SESSION["username"] = $row;
 
                    $pin = rand(0, 9) . rand(0, 9) . rand(0, 9) . rand(0, 9) . rand(0, 9) . rand(0, 9);
                     
                    $sql = "UPDATE user_table SET pin = '$pin'  WHERE user_id = '" . $row->user_id . "'";
                    mysqli_query($con, $sql);
 
 
                    header("Location: enter_pin.php");
                } else {
                    $row->is_verified = true;
                    $_SESSION["username"] = $row;
 
                    header("Location: profile.php");
                }
            } else {
                
                echo"<script>alert('Invalid Credentials(Password Incorrect) " .$number ." attempt left  ') </script>";
              
                
              
                $_SESSION['error'] = 'Password incorrect  ';
                //this is where we put our 3 attempt limit
                $_SESSION['attempt'] += 1;
                //set the time to allow login if third attempt is reach
                if ($_SESSION['attempt'] == 5) {
                    $_SESSION['attempt_again'] = time() + (1 * 60);
                    //note 5*60 = 5mins, 60*60 = 1hr, to set to 2hrs change it to 2*60*60
                }
                 
            }
        } else {
            echo"<script>alert('Invalid Credentials')</script>";
        }
    }
}
?>
所以当我运行代码时它显示 2 个错误,即
1)警告:尝试在第 148 行的 C:xampphtdocsFinalYearProjectUsersuser_login.php 中读取 null 属性“is_tfa_enabled”
2)致命错误:未捕获错误:尝试在 C:xampphtdocsFinalYearProjectUsersuser_login.php:170 中的 null 上分配属性“is_verified”:170 堆栈跟踪:#0 {main} 抛出在 C: xampphtdocsFinalYearProjectUsersuser_login.php 第 170 行
当我将第 148 行更改为 $row_data['is_tfa_enabled'] 时,错误 1 将解决
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
表中找不到
is_tfa_enabled和is_verified行 另外$row->is_verified = true;不是有效的 commande 。您不能像这样更改列值