title: Checking variables against MySQL data using PDO and PHP
body: <p>I have the following variables that were inputted in the previous login form and submitted:<br>
  </p>
  
  <pre class="lang-php prettyprint-override"><code>$login = $_POST['login'];
  $password = $_POST['password'];
  </code></pre>
  
  <p>I connect to my MySQL Database using a PDO as follows:<br>
  </p>
  
  <pre class="lang-php prettyprint-override"><code>require_once('agent-config.php');
      try {
  $conn = new PDO(A_DB_HOST, A_DB_USER, A_DB_PASSWORD);
  $conn-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  } catch (PDOException $e) {
  echo 'Connection failed: ' . $e-&gt;getMessage();
  }
  </code></pre>
  
  <p>Next, I use the variables $login and $password to select the matching username and password:
  </p>
  
  <pre class="lang-php prettyprint-override"><code>//Create SELECT query    
  $qry = $conn-&gt;prepare("SELECT * FROM members WHERE login=? AND passwd=?");
      $qry-&gt;bindParam(1, $login);
      $qry-&gt;bindParam(2, $password);
  </code></pre>
  
  <p>Lastly, I check whether the query was successful or not using:
  </p>
  
  <pre class="lang-php prettyprint-override"><code>//Check whether the query was successful or not
      if($qry-&gt;execute())
      $count = $qry-&gt;rowCount();
      echo $count;
      print_r($qry);
      if($count &gt;0) {
          //Login Successful
          session_regenerate_id();
          $member = $qry-&gt;fetch(POD::FETCH_ASSOC);
          $_SESSION['SESS_AGENT_ID'] = $member['member_id'];
          $_SESSION['SESS_login'] = $member['login'];
          session_write_close();
          header("location: agent-member-index.php");
          exit();
      }else {
          //Login failed
          header("location: login-failed.php");
          exit();
      }
  </code></pre>
  
  <p>However, the login and password are not being passed through correctly, and my result for $count is 0. I know one problem is that the password stored in the database is the .md5 encrypted version of the password, so I tried changing <code>$password</code> to<br>
  </p>
  
  <pre class="lang-php prettyprint-override"><code>$password = '.md5($_POST['password']).';   
  </code></pre>
  
  <p>but I received errors T-STRING errors. Any help would be greatly appreciated!</p>