注意:尝试获取非对象的属性

时间:2017-04-10 05:49:09

标签: php

我只是想要,如果用户登录它应该回应欢迎,如果他的名字和密码错误,请他重新进入请帮助。

require_once 'connect.php';
if (isset($_POST['logSubmit'])){
    $username = $_POST['uname'];
    $password = $_POST['psw'];
    $query ="SELECT * FROM library_db WHERE username = '$username' and password='$password' LIMIT 1";
    $queryRun=$conn->query($query);
    
    $row3 = fetch_row($queryRun);
    $row3[0];
    if($row3['username'] == $username && $row3['userPassword'] == $password){
        echo '   welcome you made it to the future';
    }else{
        echo '    please enter correct details';
        }
    }
else{
    echo 'please enter correct username and password';

2 个答案:

答案 0 :(得分:1)

在使用结果中的值之前,请始终检查该值是否存在

  if((isset($row3['username']) && $row3['username'] == $username) && 
    ((isset($row3['username']) && $row3['userPassword'] == $password))

答案 1 :(得分:0)

/* Here I am sharing working code */ require_once 'connect.php'; /* database connections */ if (isset($_POST['logSubmit'])){ $username = (isset($_POST['uname'])) ? $_POST['uname'] : ""; /* take username from post */ $password = (isset($_POST['psw'])) ? $_POST['psw'] : ""; /* take password from post */ if(trim($username) != "" AND trim($password) != ""){ /* validate username and password not empty/blank */ $query ="SELECT * FROM library_db WHERE username = '$username' and password='$password' LIMIT 1"; $result = $conn->query($query); $row = mysqli_fetch_assoc($result); /* take first row from result */ if(count($row) > 0){ /* check if row has some data */ echo 'welcome you made it to the future'; /* success */ }else{ echo 'please enter correct details'; /* no data found in result */ } }else{ echo 'please enter correct details'; /* username and/or password field empty/blank */ } }else{ echo 'please enter correct username and password'; /* logSubmit field not set */ }