tags:

views:

141

answers:

1

I have the following function and its always returning false. It does not even try to execute the statement, I know because I changed the $query = "aldfjaf lkjfsk" and it did not return an error for me. Any suggestions?

class Mysql {
private $conn;

function __construct() {
 $this->conn = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME) or 
      die('There was a problem connecting to the database.');
}

function verify_Username_and_Pass($un, $pwd) {

 $query = "SELECT *
   FROM user_table
   WHERE login_username = ? AND login_password = ?";

 if($stmt = $this->conn->prepare($query)) {
  $stmt->bind_param('ss', $un, $pwd);
  $stmt->execute();

  if($stmt->fetch()) {
   $stmt->close();
   return true;
  }
 }

}
A: 

Your not checking for error, try this:

if($stmt->execute()) {
 //code
}
else{
 die($stmt->error);
}

or:

if($stmt = $this->conn->prepare($query)){
 //code
}
else{
 die($this->conn->error);
}
Pim Jager