错误:
致命错误:未接收错误:呼叫成员函数关闭() c: xampp htdocs project project script register.php:69
堆栈跟踪:#0 c: xampp htdocs project index.php(2):include_once()#1 {main}在c: xampp xampp xampp htdocs htdocs project project script69
当我传递通过验证的正确数据时发生错误。
文件:
<?php
include_once 'functions.php';
include_once 'dbconnect.php';
// Returns the request method used to access the page
if ($_SERVER["REQUEST_METHOD"] == "POST"){
$err="";
// Validation ....
.....
// End of it
$prep_stmt = "SELECT id FROM members WHERE email = ? LIMIT 1";
$stmt = $sql_db->prepare($prep_stmt);
// check existing email
if ($stmt) {
$stmt->bind_param('s', $email);
$stmt->execute();
$stmt->store_result();
if ($stmt->num_rows == 1) {
// A user with this email address already exists
$err .= '<p class="error">A user with this email address already exists.</p>';
$stmt->close();
}
} else {
$err .= '<p class="error">Database error Line 39</p>';
$stmt->close();
}
// check existing username
$prep_stmt = "SELECT id FROM members WHERE username = ? LIMIT 1";
$stmt = $sql_db->prepare($prep_stmt);
if ($stmt) {
$stmt->bind_param('s', $username);
$stmt->execute();
$stmt->store_result();
if ($stmt->num_rows == 1) {
// A user with this username already exists
$err .= '<p class="error">A user with this username already exists</p>';
$stmt->close();
}
} else {
$err .= '<p class="error">Database error line 55</p>';
$stmt->close();
}
// Hashing, salting and inserting the values.
....
// End of file.
搜索了一些答案,为什么有问题而找不到问题。
像这样的另一个线程 - $ stmt-> colle()在if函数中。
if ($stmt) {
$stmt->bind_param('s', $email);
$stmt->execute();
$stmt->store_result();
if ($stmt->num_rows == 1) {
// A user with this email address already exists
$err .= '<p class="error">A user with this email address already exists.</p>';
$stmt->close();
}
} else {
$err .= '<p class="error">Database error Line 39</p>';
// Remove this. $stmt does not exist here due to your if/else condition
//$stmt->close();
}