아직 PHP에 비교적 익숙하지 않아서 쉽게 실수를 저지르고있을 수도 있습니다.PHP에서 오류가 발생하는 2 개의 간단한 SQL 쿼리
아래의 코드는 경고가 발생합니다 : 첫 번째는 잘 작동하고 두 번째는 이러한 오류를 throw로
Warning: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, boolean given in /home/unn_w14017307/public_html/Assignment3/JakeUploads/11March/logonProcess.php on line 87
Warning: mysqli_stmt_execute() expects parameter 1 to be mysqli_stmt, boolean given in /home/unn_w14017307/public_html/Assignment3/JakeUploads/11March/logonProcess.php on line 88
Warning: mysqli_stmt_store_result() expects parameter 1 to be mysqli_stmt, boolean given in /home/unn_w14017307/public_html/Assignment3/JakeUploads/11March/logonProcess.php on line 89
Warning: mysqli_stmt_bind_result() expects parameter 1 to be mysqli_stmt, boolean given in /home/unn_w14017307/public_html/Assignment3/JakeUploads/11March/logonProcess.php on line 90
내가,이 내가 실행할 첫 번째 쿼리와 함께 할 수있는 뭔가가 가정합니다.
첫 번째 쿼리에서 $ conn이 제대로 작동하므로 연결 문제가 아닙니다.
<?php
$username = filter_has_var(INPUT_POST, 'username') ? $_POST['username']: null;
$password = filter_has_var(INPUT_POST, 'password') ? $_POST['password']: null;
include 'database_conn.php'; // make db connection
/* Query the users database table to get the password hash for the username entered by the user in the logon form */
$sql = "SELECT password FROM Users WHERE username = ?";
$typeSql = "SELECT type FROM Users WHERE username = $username";
$stmt = mysqli_prepare($conn, $sql); // prepare the sql statement
/* Bind the $username entered by the user to the prepared statement. Note the “s” part indicates the data type used – in this case a string */
mysqli_stmt_bind_param($stmt, "s", $username);
mysqli_stmt_execute($stmt); // execute the query
mysqli_stmt_store_result($stmt); //store result so second query can be used
/* Get the password hash from the query results for the given username and store it in the variable indicated */
mysqli_stmt_bind_result($stmt, $returnedPass);
/* Check if a record was returned by the query. If yes, then there was a username matching what was entered in the logon form and we can now test to see if the password entered in the logon form is the same as the stored (correct) one in the database. */
if (mysqli_stmt_fetch($stmt)) {
if($password === $returnedPass)
{
mysqli_stmt_close($stmt);
$stmt = mysqli_prepare($conn, $typeSql);
mysqli_stmt_bind_param($stmt, "s", $username);
mysqli_stmt_execute($stmt);
mysqli_stmt_store_result($stmt);
mysqli_stmt_bind_result($stmt, $accountType);
$_SESSION['uName'] = $username;
$_SESSION['logged-in'] = true;
$_SESSION['type'] = $type;
echo "<p>Password valid</p>";
echo "<p>Username: $username</p>";
echo "<p>Account type: $type</p>";
}
else
{
echo "<p>Password invalid</p>";
}
}
else {
echo "<p>Sorry we don't seem to have that username.</p>";
}
mysqli_stmt_close($stmt);
mysqli_close($conn);
?>
(!) 참고 : 내가 좋아하는 일을 할 것, 안전한 로그인을위한 그러나
: 왜 당신은 두 개의 별도의 쿼리를 사용하는
또 다른 점은이에 대한 쿼리를 결합 할 수 있다는 것입니다 ? 이 작업을 하나의 작업으로 수행 할 수 있습니다. –
쿼리에 대해 mysqli_error ($ conn)로 실제 오류가 있는지 확인하십시오. –
하나의 쿼리에서이 작업을 어떻게 수행합니까? mysqli_stmt_bind_result를 사용하여 쿼리에서 암호와 결과를 별도의 변수로 분리하는 방법을 잘 모르겠습니다. –