假设我有这个PHP代码:
$emailCheck = $_POST['emailCheck'];
echo "Checking: " . $emailCheck; // Checking: test@test.net
var_dump($stmt);
$sql = "SELECT id, email FROM members WHERE email=?";
$stmt = $mysqli->prepare($sql);
$stmt->bind_param("s", $emailCheck);
$stmt->execute();
$stmt->bind_result($m_id, $m_email);
$stmt->execute();
和我的数据库:
如您所见,我可以从PHPMyAdmin获取它。但是,PHP页面是另一个故事,因为我得到:
致命错误:在...
中的非对象上调用成员函数bind_param()
有违规行:
$sql = "SELECT id, email FROM members WHERE email=?";
我做错了什么?
感谢。
完成var_dump($stmt);
后,我得到了:
object(mysqli_stmt)[4]
public 'affected_rows' => null
public 'insert_id' => null
public 'num_rows' => null
public 'param_count' => null
public 'field_count' => null
public 'errno' => null
public 'error' => null
public 'error_list' => null
public 'sqlstate' => null
public 'id' => null
编辑:尽管我尽可能具有描述性,但我还是被投票了。优等的。
答案 0 :(得分:3)
请确保$mysqli->stat()
与您的mysql连接正常。
答案 1 :(得分:1)
$stmt
可能是假的。
试试这段代码:
$emailCheck = $_POST['emailCheck'];
echo "Checking: " . $emailCheck; // Checking: test@test.net
$sql = "SELECT id, email FROM members WHERE email=?";
if ($stmt = $mysqli->prepare($sql)) {
$stmt->bind_param('s', $emailCheck);
$stmt->execute();
$stmt->bind_result($m_id, $m_email);
$stmt->execute();
}
else {
printf("Errormessage: %s\n", $mysqli->error);
}