我已经使用mysql数据库和php创建了一个简单的登录身份验证,但出现错误“ 致命错误:在非对象中调用成员函数prepare()”。
<?php
$mysqli = new mysqli('localhost','root','','secure_login')
if (isset($_POST['user'],$_POST['pass'])){
$username = $_POST['user'];
$password = $_POST['pass'];
if (login($username,$password,$mysqli == true)){
//login sucess
header('Location: ../stu_pages/welcome.html');
}else{
//login failed
header('Location: ../index.html');
}
}
function login($username,$password,$mysqli){
if ($stmt = $mysqli->prepare("SELECT `id`, `username`, `password` FROM `member` WHERE `username` = ?")){
$stmt->bind_param("s", $username);
$stmt->execute();
$stmt->store_result();
if ($stmt->num_rows === 0){
$stmt->bind_result($user_id,$user_name,$db_password);
$stmt->fetch();
if ($password == $db_password){
return true;
}else{
return false;
}
}else{
echo 'no record found';
}
}
}
?>
答案 0 :(得分:-1)
if (login($username,$password,$mysqli == true))
替换为
if (login($username,$password,$mysqli) == true)