I have a login database with user and password and a html file with input type for username and password..
in my class for the login:
class login
{
protected $_username;
protected $_password;
public function __construct($username, $password) //$username and $password values will be from the $_POST['username and password'] when the user submits the username and password
{
$this->username = $username;
$this->password = md5($password);
}
public function login()
{
try {
$pdo = dbConnect::getConnection();
$smt = $pdo->prepare("SELECT * FROM users WHERE username = ?");
$smt->bindParam(1, $this->username);
$smt->execute();
echo "<pre>";
print_r($smt->fetch(PDO::FETCH_OBJ)); //testing if $smt will return results..yes it returned
if($smt->fetch()) {
print_r($smt->fetch(PDO::FETCH_OBJ)); //doesn't return ??this is my question... all other arguments inside this if loop is not executed..
while($row = $smt->fetch(PDO::FETCH_OBJ)) {
echo "one";
if($row->password == $this->password) {
header("Location: admin.php");
}
else {
echo '<div class="alert alert-error alert-block"><button type="button" class="close" data-dismiss="alert">×</button><h4>Error!</h4>username and password do not match!</div>';
}
}
}
else {
echo '<div class="alert alert-error alert-block"><button type="button" class="close" data-dismiss="alert">×</button><h4>Error!</h4>Username does not exist!</div>';
}
}
catch (PDOException $e) {
die($e->getMessage());
}
}
}
the problem is that in PDO, it will not return data that i've been requesting after the if($smt->fetch()) which is used to know if the query returned a result.. before the fetch, the print_r returns data... i can't continue my code because of this..im new to OOP and PDO that's why i can't handle this unlike from mysql or mysqli functions.. im new to PDO, also im using sqlite here..