2015-10-17 44 views
1

我正在MAMP中尝试进行登录功能。
我的连接代码是:PHP bind_param未定义

$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 Fatal error: Call to undefined method mysqli::bind_param() in /Users.../Site/include/functions.php on line 24

回答

0

你需要调用bind_param的发言,就像这样:

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

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

+0

这是问题,非常感谢 –

+0

不客气,乔丹。 –