我一直在将我的代码转换为PDO标准,但出于某种原因,我无法返回行数。我认为它没有正确存储变量,但我非常肯定。
// Define $username and $password
$email=$_POST['email'];
$hash=$_POST['hash'];
// To protect MySQL injection for Security purpose
$email = stripslashes($email);
$hash = stripslashes($hash);
$email = mysql_real_escape_string($email);
$hash = hash('SHA256', '$hash');
$dbConnect = 'mysql:dbname=test;host=localhost';
$username = "test";
$password = "test";
try{
$dbConnect = new PDO($dbConnect, $username, $password);
} catch (PDOException $error) {
echo 'Error Connecting: ' . $error->getMessage();
}
$query = $dbConnect->prepare("SELECT * FROM user WHERE 'hash'=:hash AND 'email'=:email");
$query->bindValue(':hash', $hash);
$query->bindValue(':email', $email);
$query->execute();
$rows = $query->rowCount();
echo $rows;
if ($rows == 1) {
session_start(); // Starting Session
$_SESSION['login_user']=$email; // Initializing Session
header('Location: home.php'); // Redirecting To Home Page
} else {
$loginError = "Username or Password is invalid";
}
mysql_close($connection); // Closing Connection