我认为我的问题出在我的代码的 MySQL 部分中,我需要它来计算至少一个表行为真并继续该if
语句,否则执行该else
语句。当我运行代码时,除了页面顶部的用户名和密码之外,它不会显示错误,只是一个空白页面,echo
我只是在检查它们是否通过并且它们是。我的代码如下:
<?php
$myusername=$_POST['userName'];
$mypassword=$_POST['password'];
echo $mypassword;
echo "<br>" . $myusername;
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
try {
$conn = new PDO('mysql:host=localhost;dbname=timecard', 'username', 'password');
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare('SELECT COUNT(*) FROM employees WHERE `userName`= :userName AND `password`= :password');
$stmt->execute(array(':userName' => $myusername, ':password' => $mypassword));
} catch(PDOException $e){
echo'ERROR: ' . $e->getMessage();
}
$res = $conn->query($stmt);
if($res->fetchColumn() > 0){
session_register("myusername");
session_register("mypassword");
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?>