title: How to check username and password match
body: <p>I'm trying to check if a users entered username and password matches an entry from the database using PDO, but for some reason cannot seem to get it working. </p>
  
  <p>The database table is called user_info and the rows from which i'm trying to grab the username and password from are <code>username</code> and <code>pass</code> respectively. I'm not entirely sure how to check if the users input information matches a database entry, then make a decision on where to send them based on if it returns true or false.</p>
  
  <p>Also, i've obviously got the prerequisites such as including a file that connects to the database, which i know whose information is correct.</p>
  
  <p>I've had a stab in the dark on the <code>if ($username)</code> etc, but clearly it's incorrect.</p>
  
  <p>HTML</p>
  
  <pre><code>            &lt;form method="post"&gt;
                  &lt;label for="username2"&gt;Username&lt;/label&gt;
                  &lt;input type="text" name="username"&gt;
                  &lt;label for="password"&gt;Password&lt;/label&gt;
                  &lt;input type="text" name="password"&gt;
                  &lt;input type="submit" value="Login" name="login"&gt;
              &lt;/form&gt;
  </code></pre>
  
  <p>PHP</p>
  
  <pre><code>                $username = $_POST['username'];
                  $password = $_POST['password'];
  
                  try {   
  
                      $result = $db-&gt;prepare("SELECT * FROM user_info WHERE username = :user AND pass = :pass");
                      $result-&gt;bindParam(':user', $username);
                      $result-&gt;bindParam(':pass', $password);
                      $result-&gt;execute();
                      $rows = $result-&gt;fetch(PDO::FETCH_NUM);
                  }
  
                  catch (Exception $e) {
                      echo "Could not retrieve data from database";
                      exit();
                  }
  
                  if ($username == "test" &amp;&amp; $password == "test") {
                      $_SESSION['username'] = $username;
                      redirect('/add-property.php');
                  } else {
                      if (isset($_POST['login'])) {
                          echo "Username or password incorrect";
                      }
                  }
  </code></pre>