2017-06-29 3 views
1

このコードスニペットは警告をスローしています。mysqli_fetch_array()は、パラメータ1がmysqli_resultであることを前提としています。prepare文とexecute文を使用した後でmysqli_fetch_arrayを使用してresultにアクセスするには?

$sql =$conn->prepare("SELECT password FROM users WHERE username =?"); 
$sql->bind_param("s",$pass); 
$result=$sql->execute(); 
$row=mysqli_fetch_array($result); 
    if(password_verify($pass,$row[0])&&mysqli_num_rows($result)==1) 
    { 
    $_SESSION['username']=$user; 
    $_SESSION['success']="Logged in Successfully"; 
    header("location: notice.php"); 
    } 
    else 
    $submitErr="Your login credentials are incorrect"; 

答えて

0
use : 
$stmt =$conn->prepare("SELECT password FROM users WHERE username =?"); 
$stmt->bind_param("s",$input_username); //bind the query with input parameter user name 
$stmt->execute(); 
$result=$stmt->store_result(); 
$stmt->bind_result($selected_password) 
$num_row = $stmt->num_rows; 
if($num_row > 0) 
{ 
    $stmt->fetch(); // here you will get your selected password 
    if(password_verify($input_password,$selected_password)) 
    { 
    //Your action is password verification done 
    } 
    else 
    { 
    //wrong password action 
    } 
} 
else 
{ 
    // wrong username password action 
} 
関連する問題