1

我在 MAMP 工作,试图创建一个登录功能。
我的连接代码是:

$servername = "localhost";
$username = "root";
$password = "root";
$db = "world";

$mysqli = new mysqli($servername, $username, $password, $db);

if($mysqli->connect_error){
    die("Connection failed: " . $conn->connect_error);
}

我的登录功能:

if (isset($_POST['email'], $_POST['p'])){
$email = $_POST['email'];
$password = $_POST['p']; //hashed password

if(login($email, $password, $mysqli) == true){
    header('Location: ../protected_page.php');
    }else{
    echo 'failed login';
    }
}
function login($email, $password, $mysqli){
if($stmt = $mysqli->prepare("SELECT USERID, USERNAME, PASSWORD, SALT FROM USERS WHERE EMAIL = ? LIMIT 1")){
    $stmt = $mysqli->bind_param('s', $email);
    $stmt->execute();
    $stmt->store_result();
    $stmt->bind_result($user_id, $username, $db_password, $salt);
    $stmt->fetch();
}

错误:

[17-Oct-2015 08:46:06 Europe/Berlin] PHP 致命错误:在第 24 行的 /Users.../Site/include/functions.php 中调用未定义的方法 mysqli::bind_param()

4

2 回答 2

1

http://php.net/manual/en/mysqli-stmt.bind-param.php

从手册中可以看出,这不是 mysqli 对象的方法,而是 mysqli_stmt 对象的方法。

当你运行时,你也在破坏 mysqli_stmt 对象$stmt = $mysqli->bind_param('s', $email);

于 2015-10-17T06:55:36.427 回答
0

您需要调用bind_param您的声明,如下所示:

$stmt->bind_param('s', $email);

在此之前您已经定义$stmt了一行。$mysqli没有bind_param功能。

于 2015-10-17T06:56:33.983 回答