Im trying to create a login script using PDO
<?php
php include 'inc/functions.php';
if(isset($_POST['UserName'],$_POST['Password']))
{
$UserName = $_POST['UserName'];
$Password = $_POST['Password'];
try {
$sql = "SELECT `employeeNumber`, `password`,`userName` FROM `usernames-passwords` WHERE `userName` = :UserName AND `password` = md5(:Password)";
$stmt = $conn->prepare($sql);
$stmt->execute(array(
":UserName" => $UserName,
":Password" => $Password
));
$count = $stmt->rowCount();
$row = $stmt -> fetch();
if($count==1)
{
$_SESSION['employeeNumber'] = $row['employeeNumber'];
$_SESSION['UserName'] = $UserName;
$_SESSION['Password'] = $Password;
header( "location: welcome.php");
exit();
}
} catch (PDOException $e) {
echo "Database error: ".$e->getMessage();
}
$conn = null;
}
?>
...
...
HTML
...
...
<?php echo '<pre>' . print_r($_POST, TRUE) . '</pre>';
echo $sql;
echo '<pre>' . print_r($_SESSION, TRUE) . '</pre>'; ?>
the result…
The query works (correct username/password) so why arent the SESSION vars being set?