I’m currently getting an undefined object fetchall error and PDO selection script. because from what I can see the PDO variable is being defined. But maybe that’s just me. There’s a good chance that I’m missing something.
In a config file. I have defined all variables needed and started the PDO connection as the variable $pdo.
and here’s the section of code that is giving me the grief
$queryselectemail = "SELECT COUNT(*) FROM users WHERE email = :email";
$values = array('email' => $email);
try {
$tryemail = $pdo->prepare($queryselectemail);
$tryemail->execute($values);
} catch (PDOException $e) {
$title = "There was an error :(";
$output = "We are sorry but there has been an error! The error is a PDO/Mysql error and it is {$e->getMessage()}";
}
}
if($tryemail->fetchAll() < 1){
/* code to insert user data */
}
however I am just getting the error. I made if the e-mail already exists in the database. (Not shown above)
Okay, I think this is a workflow issue, you will always have 1 row returned by your query because you are doing a COUNT(*). For a non-matching e-mail, the row will have a value of 0, for a matching e-mail, it will have a value of 1 (either way, you get 1 row returned with 1 value).
The second issue I see, is your fetchAll is assuming it returns an int value, it returns an array, so you might have to use $tryemail->fetchAll()[0][0] (signifies 1st row and 1st column. or if PHP doesn’t support that syntax the following may be the correct approach)
$rows = $tryemail->fetchAll();
if ($rows[0][0] < 1)
{
// insert user data
for got to post. But i got it resolved. What i eneded up doing was if what was retured was more then one i ened saying the email was in use. then in the else state that is where i insert the data.