title: PHP Prepared Statements login form
body: <p>I have been coding a login script in PHP using prepared statements however I can't get it to work, can anyone point out why this isn't working? </p>
  
  <p>Whenever I log in all I get is the "Statement failed!".</p>
  
  <pre><code>//Start session
  session_start();
  
  //Include database connection details
  require_once('config.php');
  
      //Sanitize the POST values
  $login = clean($_POST['login']);
  $password = clean($_POST['password']);
  
  $query = $dbconn -&gt; prepare("SELECT * FROM members WHERE login=? AND passwd=?");
  $query -&gt; bind_param("ss", $login, $password);
  
  if($query-&gt;execute() == true) {
      $query -&gt; bind_result($result);
      $query -&gt; fetch();
      if($result){
              $member = mysqli_fetch_assoc($result);
              session_regenerate_id();
              $_SESSION['SESS_MEMBER_ID'] = $member['member_id'];
              $_SESSION['SESS_FIRST_NAME'] = $member['firstname'];
              $_SESSION['SESS_LAST_NAME'] = $member['lastname'];
              $_SESSION['SESS_IS_ADMIN'] = $member['admin'];
              session_write_close();
              echo $_SESSION['SESS_MEMBER_ID'];
              echo $_SESSION['SESS_FIRST_NAME'];
              echo "Test!";
              exit();
      }else{
              echo "Statement failed";
      }
  }
  /* Close statement */
  $query -&gt; close();
  </code></pre>
  
  <p>In config.php there is the following:</p>
  
  <pre><code>$dbconn = new mysqli('localhost', 'root', 'password', 'bookingsystem');
  </code></pre>
  
  <p>And the database structure for the users looks like this:</p>
  
  <pre><code>`members` (`member_id`, `firstname`, `lastname`, `login`, `passwd`, `admin`) VALUES
  (1, 'Steve', 'Stone', 'Admin', '5f4dcc3b5aa765d61d8327deb882cf99', 1);
  </code></pre>