因此,我一直在尝试编写基本的PHP登录脚本,而我发现的这两种方法似乎对我不起作用。当我输入正确的用户名和密码时,数组始终为空,并且$ count最终为0。我花了几个小时试图在各处找到解决方案,并且可以肯定问题出在我的数据库中,无论如何请看一下: `
$username = $_POST['username'];
$password = $_POST['password'];
$conn = mysqli_connect("localhost", "root", "");
mysqli_select_db($conn, "login_test");
if ( !$conn ) { echo "Error".mysqli_connect_error(); exit(); }
$query = "SELECT * FROM users where Username = '$username' and Password = '$password' ";
$result = mysqli_query($conn, $query) or die(mysqli_error($conn));
$row = mysqli_fetch_array($result);
$count = mysqli_num_rows($result);
if( $row['Username'] == $username && $row['Password'] == $password ) {
echo "Success";
}
elseif( count == 1 ) {
echo "Success";
}
else {
"Failed to log in";
}
我正在使用wamp服务器和MySQL。预先感谢!