title: PDO login validation
body: <p><strong>I am trying to create a user login verification script. I have two pages one is called checklogin.php which is the code bellow :</strong>   </p>
  
  <pre><code>&lt;?php 
  session_start();
  
  $host="localhost"; // Host name
  $username="root"; // Mysql username
  $password="testdbpass"; // Mysql password
  $db_name="test"; // Database name
  $table = "users";
  
  // Connect to server via PHP Data Object
  $db = new PDO("mysql:host=localhost;dbname=test;", $username, $password);
  
  $username = $_POST['username'];
  $password = $_POST['password'];
  
  
  if(isset($_POST['username']) &amp;&amp; !empty($_POST['username']) 
  AND
  isset($_POST['password']) &amp;&amp; !empty($_POST['password']))
  
  $pass = crypt($password . $row['salt']);
  $statement-&gt;bindParam(':username', $username);
  $query = ("SELECT * FROM $table WHERE username = :username");
  $statement = $db-&gt;prepare($query);
  $output = 'Login Error';
  
  if ($statement-&gt;execute() &amp;&amp; $row = $statement-&gt;fetch())
  
  {
      if ($row['password'] === $pass)
  
          {
          if ( $row['activated'] !== 0 ) {
          $output = 'Not activiated wait for Administrator Approval';
          $_SESSION['username'] = $username;
          }
          $output = 'Logged In';
          }
      }
  
      echo $output;
  
     $db = null;
     ?&gt;
  </code></pre>
  
  <p><strong>and I have a register_script.php page which is this code :</strong> </p>
  
  <pre><code>&lt;?php 
  
  $host="localhost"; // Host name
  $username="root"; // Mysql username
  $password="testdbpass"; // Mysql password
  $db_name="test"; // Database name
  
  // Connect to server via PHP Data Object
  $dbh = new PDO("mysql:host=localhost;dbname=test;", $username, $password);
  
  CRYPT_BLOWFISH or die ('No Blowfish found.');
  
  //This string tells crypt to use blowfish for 15 rounds.
  $Blowfish_Pre = '$2y$15$';
  $Blowfish_End = '$';
  
  // Blowfish accepts these characters for salts.
  $Allowed_Chars =
  'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789./';
  $Chars_Len = 63;
  
  
  $Salt_Length = 45;
  $salt = "";
  
  for($x=0;$x&lt;5000;$x++)
  {
  $salt .= $Allowed_Chars[mt_rand(0,$Chars_Len)];
  }
  $bcrypt_salt = $Blowfish_Pre . $salt . $Blowfish_End;
  
  $password = $_POST['password'];
  
  $hashed_password = crypt($password, $bcrypt_salt);
  
  // Insert statements with PDO 
  
  try {
  $query = $dbh-&gt;prepare("INSERT INTO `users_blowfish` (username, email,   fname, lname,   salt, password) 
                             VALUES (:username, :email,   :first, :last, :salt, :hash)");
  
      $params = array(
                      'username' =&gt; $_POST['username'],
                      'email' =&gt; $_POST['email'], 
                      'first' =&gt; $_POST['fname'],
                      'last' =&gt; $_POST['lname'],
                      'salt' =&gt; $bcrypt_salt,
                      'hash' =&gt; $hashed_password);
  
          $query-&gt;execute($params);
  
  }
  
  catch (PDOException $e) {
      error_log($e-&gt;getMessage());
      die("An error occured, contact admin");
  }
  
  $dbh= null;
  
  ?&gt;
  
   &lt;html&gt;
  &lt;body&gt;
      &lt;p&gt; 
          Thank you for registering your account. Please wait for   administrator approval before doing anything else. Thank you - System Administrator. 
      &lt;/p&gt;
  &lt;/body&gt;
  &lt;/html&gt; 
  </code></pre>
  
  <p>I try to login and I am getting a error log in my apache2 error file state : </p>
  
  <p><strong>[Sat Dec 22 11:47:36 2012] [error] [client Desktop] PHP Parse error:  syntax error, unexpected T_VARIABLE in /var/www/version2/checklogin.php on line 23, referer: *<em><code>http://localhost/version2/</code></em>*</strong></p>
  
  <p>I can't seem pinpoint the problem with this. I have referenced php.net on how to work with PDO but to no avail. The problem is being caused by the checklogin.php as the register_script.php is working fine (tested from a couple days ago).
  Any help would be lovely thank you.</p>
  
  <p>Edit 1: </p>
  
  <p>Line 23 goes as fallows : <code>$statement-&gt;bindParam(':username', $username);</code></p>
  
  <p>Edit 2:  Lines that could be causing the problem : </p>
  
  <pre><code>`$pass = crypt($password . $row['salt']);
   $statement-&gt;bindParam(':username', $username);
   $query = ("SELECT * FROM $table WHERE username = :username");
   $statement = $db-&gt;prepare($query);
   $output = 'Login Error';`
  </code></pre>