PHP bind_param未定义

时间:2015-10-17 06:49:44

标签: php mysqli bindparam

我在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();
}

错误:

  

[2015年10月17日08:46:06欧洲/柏林] PHP致命错误:在第24行的/Users.../Site/include/functions.php中调用未定义的方法mysqli :: bind_param()< / p>

2 个答案:

答案 0 :(得分:1)

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

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

运行$stmt = $mysqli->bind_param('s', $email);

时,您也在销毁mysqli_stmt对象

答案 1 :(得分:0)

你需要为你的陈述打电话bind_param,如下所示:

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

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