Hey there,
I am trying to count the number of rows returned by a PDO. I have tried to use http://php.net/manual/en/pdostatement.rowcount.php (Example #2) to try and make my select query.
here’s the code
$query['1'] = 'SELECT COUNT(*) FROM users WHERE `email` = :email AND `password` = :password';
$x = $pdo->prepare($query['1']);
$values['1'] = array('email' => $email, 'password' => $password);
if($res = $x->execute($values['1'])){
if($res->fetchColumn() == 1){
$query['2'] = 'SELECT * FROM users WHERE email= :email AND password= :password';
$y = $pdo->prepare($query['2']);
$values['2'] = array('email' => $email, 'password' => $password);
session_start();
foreach($y->execute($values['2']) as $row)
{
$_SESSION['id'] = $row['id'];
$_SESSION['email'] = $row['email'];
$_SESSION['name'] = $row['nameFirst'];
}
echo "<div class=\\"sucess\\">\
<p>You have been logged in. This page well redirect you to our home page in 5 seconds or less</p>/n</div>";
}
}
else{
echo "<p class=\\"loginError\\">Your email or Password was wrong, please try again!</p>";
require('../../views/forms/login.php');
}
And i am getting an error on line 18 : Call to a member function fetchColumn() on a non-object in /var/www/ageasy/lib/account/login.php on line 18.
Any help would be appreciated.