title: Verifying username/password via MySQL server using PDO functions
body: <p>I am having some problem connecting properly to the MySQL server using the PDO function.
  I can't query what I need from the database and I am not quite sure what PDO functions to use.
  I GET 0 as a result of this.
  I wish to verify the password and username I enter via the database and make an if statement that launches the session if the information is correct.</p>
  
  <p>Here is my  UPDATED code:</p>
  
  <pre><code>&lt;?php
  // if a value is given
  if (isset($_POST['username' &amp;&amp; 'password'));
  {
  
      // starts the session created if login info is correct
      session_start();
  
      // connectivity to MySQL server
      $db = new PDO('mysql:host=host;dbname=name', 'username', 'password');
  
      // information entered in form made into a variable
      $username = PDO::quote($_POST['username']); 
      $password = PDO::quote($_POST['password']);
  
      // after pressing login, checking if the variables exist in the database
      if ($_POST['button'] == 'Login')
      {
          $query = $db-&gt;query("SELECT COUNT(*) FROM login WHERE username=:username AND password=:password");
          $query-&gt;bindValue(':username', $username, PDO::PARAM_STR);
          $query-&gt;bindValue(':password', $password, PDO::PARAM_STR);
          $query-&gt;execute();
  
          // Check the number of rows that match the SELECT statement 
          if($query = $db-&gt;fetch(PDO::FETCH_OBJ)) 
          {
              echo "No records found";
          }
          else
          {
              header("Location: members.php");
              $_SESSION['username'] = $_POST['username'];
          }
      }   
      // After pressing register, stores variable and adds it in register field
      else if ($_POST['register'] == 'Register')
      {
          header("Location: register.php");
          $_SESSION['usernamereg'] = $_POST['username'];
      }
  
      // If no button is pressed, send to index
      else
      {
          header("Location: http://www.gjertgjersund.com");
      }
  
  // closes the if value is given statement
  }
  ?&gt;
  
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt; Folder &lt;/title&gt;
      &lt;link rel="stylesheet" type="text/css" href="frontpage.css"&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
      &lt;div id="box"&gt;
      &lt;div id="wrap"&gt;
  
  
          &lt;center&gt;
          &lt;img src="./img/logo.png" alt="logo"&gt;
  
          &lt;form action='index.php' method='POST' autocomplete='off'&gt;
  
          &lt;div class="usernameform"&gt;
          &lt;input type='text' name='username' style='border: none; font-size: 20px;'&gt;
          &lt;/div&gt;
  
          &lt;br /&gt;
  
          &lt;div class="passwordform"&gt;
          &lt;input type='password' name='password' style='border: none; font-size: 20px;'&gt;
          &lt;/div&gt;
  
          &lt;br /&gt;
  
          &lt;div class="registerlogin"&gt;
          &lt;input type='submit' name='button' value='Login' class='input'&gt;
          &lt;input type='submit' name='register' value='Register' class='inputtwo'&gt;
          &lt;/div&gt;
  
          &lt;/form&gt;
          &lt;/center&gt;
  
      &lt;/div&gt;
      &lt;/div&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>