I think my problem is in the MySQL sections of my code I need it to count at least one table row to be true and continue the if
statement otherwise do the else
statement. When I run the code it does not display an error just a blank page besides the username and password echo
at the top of the page I was just checking to see if they were passing and they are. My code is below:
<?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";
}
?>