PHP bind_param未定义 [英] PHP bind_param not defined
本文介绍了PHP bind_param未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在MAMP中尝试建立登录功能.
我的连接代码是:
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);
}
我的登录功能:
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日欧洲/柏林] PHP致命错误:在第24行的/Users.../Site/include/functions.php中调用未定义方法mysqli :: bind_param() /p>
[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
推荐答案
您需要调用bind_param
进行声明,例如:
You need to call bind_param
for your statement, like this:
$stmt->bind_param('s', $email);
在此之前,您已经定义了$stmt
行. $mysqli
没有bind_param
函数.
You have already defined $stmt
one line before that. $mysqli
does not have a bind_param
function.
这篇关于PHP bind_param未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文