Brenden Clerget
Brenden Clerget

Reputation: 137

PDO keeps throwing error on email check?

if(!empty($_POST['email'])) {
    $params = array( ':email' => $email );
    $sql = "SELECT `email` FROM `tablename` WHERE email = :email";
}

else return false;

$stmt = $user->query($sql, $params);
echo ( $stmt->rowCount() > 0 ) ? $exists = false : $exists = true;
if($exists) { header("Location:theurlifemailalreadyexists");  };

Warning: PDOStatement::execute() [pdostatement.execute]: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@gmail.com' at line 1 in ** on line 87

How can I get it to stop throwing that thing? It's throwing it at the email address EVERY TIME.

Upvotes: 0

Views: 54

Answers (1)

Hanky Panky
Hanky Panky

Reputation: 46900

What's this?

 SELECT `email` FROM `tablename` WHERE email = {$user->secure($_POST['email'])}
                                               ^

This should be

SELECT `email` FROM `tablename` WHERE email = :email

Since the parameter you are replacing is :email

$params = array( ':email' => $email );

Upvotes: 3

Related Questions