我更新了我的代码并使用了 mysqli 这次我没有收到任何错误但它现在不允许我登录。
<?php
$host = 'my host';
$user = 'me';
$PW = 'my password';
$dB = 'login';
$table = 'members';
$field = 'username';
/* Create a new mysqli object with database connection parameters */
$mysqli = new mysqli($host, $user, $PW, $dB);
if(mysqli_connect_errno()) {
echo "Connection Failed: " . mysqli_connect_errno();
exit();
}
//Grab User submitted information
$name = $_POST['username']; //login name
$pass = $_POST['password']; //login password
/* Create a prepared statement */
if($stmt = $mysqli -> prepare("SELECT f_name FROM $table WHERE $field=?
AND password=?")) {
/* Bind parameters
s - string, b - blob, i - int, etc */
$stmt -> bind_param("ss", $name, $pass);
/* Execute it */
$stmt -> execute();
/* Bind results */
$stmt -> bind_result($result);
/* Fetch the value */
$stmt -> fetch();
if ($result == NULL) {
echo "That combo of username and password is wrong!";
}
else{
echo "Hello " . $result;
}
/* Close statement */
$stmt -> close();
}
/* Close connection */
$mysqli -> close();
?>
我认为它现在可以工作,但即使我输入正确的 ID 和密码,它也会说我没有。我不知道它为什么会这样做。