Hey there,
i am trying to work on the login code, i would like to know if there is a PDO function to return the total number of found rows. If i remeber i thought there was a function call rowCount but maybe i am mistaken, but i don’t think it well do what i want it to do. Thanks for the help PDO is still new to me.
Here’s the code i tried:
<?php
$Dbuser = 'colin';
$passwordDb = 'qeMQjea5uqdZc3W8';
try {
$dbconnect = new PDO("mysql:host=localhost;dbname=ageasy",$Dbuser,$passwordDb);
}
catch (PDOException $e)
{
echo '<p class="db_Erorr">We can not connect to the database at this time. Please try at a later time</p>'.$e->getMessage();
}
$emailUnSafe = $_POST['email'];
$email = strip_tags(trim($emailUnSafe));
$passWdUnSafe = $_POST['password'];
$passWdRaw = stripslashes(htmlspecialchars(trim($passWdUnSafe)));
$passwd = hash('sha512',$passWdchar);
$salt['0'] = 'salt';
$salt['1'] = 'salt';
$password = $salt['1']."".$passwd."".$salt['0'];
$sql = 'SELECT COUNT(*) FROM members WHERE email=:email AND password=:password';
$s = $dbconnect->prepare($sql);
$s->bindValue(':email',$email);
$s->bindValue(':password', $password);
if ($res = $s->execute())
{
if($res->fetchColumn == 1)
{
$sql = "SELECT * FROM members WHERE email=:email AND password=:password";
$res->setFetchMode(PDO::FETCH_OBJ);
while($row = $result->fetch())
{
$_SESSION['email'] = $row->email;
$_SESSION['userId'] = $row->id;
$_SESSION['nameFirst'] = $row->nameFirst;
$_SESSION['farmName'] = $row->farmName;
}
}
else
{
echo '<p> We could not find your account please check the email or password</p>';
}
}
I need a bit of help, i have little clue how to do row count’s in PDO
The link i posted has all the information you need, all you need to do is the following.
Change
if ($res->fetchColumn == 1)
To
if ($res->rowCount() > 0)