PHP bind_param not defined [duplicate]

爷,独闯天下 提交于 2019-12-24 13:49:07

问题


I am working in MAMP trying to make a login function.
My connection code is:

$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);
}

My login function:

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

Error:

[17-Oct-2015 08:46:06 Europe/Berlin] PHP Fatal error: Call to undefined method mysqli::bind_param() in /Users.../Site/include/functions.php on line 24


回答1:


You need to call bind_param for your statement, like this:

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

You have already defined $stmt one line before that. $mysqli does not have a bind_param function.




回答2:


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

From the manual, you can see, this is not a method of the mysqli object but of the mysqli_stmt object.

You are also destroying the mysqli_stmt object when you run $stmt = $mysqli->bind_param('s', $email);



来源:https://stackoverflow.com/questions/33183742/php-bind-param-not-defined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!