PHP validation using PDO not working <p>I am new to PDO. I have included validation in the following code but it doesnt seem to work and no message appears if users enter the wrong username/password. Please show me where I am going wrong. I have numerous times to get this working but no luck. Thanks</p> <pre><code>&lt;?php require("config.php"); $submitted_username = ''; if(!empty($_POST)){ $query = " SELECT id, username, password, salt, email FROM users WHERE username = :username "; $query_params = array( ':username' =&gt; $_POST['username'] ); try{ $stmt = $db-&gt;prepare($query); $result = $stmt-&gt;execute($query_params); } catch(PDOException $ex){ die("Failed to run query: " . $ex-&gt;getMessage()); } $login_ok = false; $row = $stmt-&gt;fetch(); if($row){ $check_password = hash('sha256', $_POST['password'] . $row['salt']); for($round = 0; $round &lt; 65536; $round++){ $check_password = hash('sha256', $check_password . $row['salt']); } if($check_password === $row['password']){ $login_ok = true; } } if($login_ok){ unset($row['salt']); unset($row['password']); $_SESSION['user'] = $row; header("Location: secret.php"); die("Redirecting to: secret.php"); } else{ print("Login Failed."); $submitted_username = htmlentities($_POST['username'], ENT_QUOTES, 'UTF-8'); } } ?&gt; </code></pre> <p><strong>Config.php</strong></p> <pre><code>&lt;?php // These variables define the connection information for your MySQL database $username = "xxxx"; $password = "xxxx"; $host = "xxxxxxx"; $dbname = "xxxxxx"; $options = array(PDO::MYSQL_ATTR_INIT_COMMAND =&gt; 'SET NAMES utf8'); try { $db = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8", $username, $password, $options); } catch(PDOException $ex) { die("Failed to connect to the database: " . $ex-&gt;getMessage()); } $db-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db-&gt;setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); header('Content-Type: text/html; charset=utf-8'); session_start(); ?&gt; </code></pre>