The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Need help with login form Reply To: Need help with login form


Hi Codi. PDO is just an interface for your database interactions. Your actual SQL statements will be the standard ones you’d normally use.

Checking whether the username exists is as simple as checking if your statement execute function returned a record. I would do it when I try to retrieve the password.

I’m on my phone, so code will be brief and possibly inaccurate!

$sql = "SELECT password FROM users WHERE username = :username";
$stmt = $db->prepare($sql);
$stmt->execute(array(":username" => $username));
// Executed, but no record returned.
// Username is UNIQUE, so it'll be one record or none
$row = $stmt->fetch();
// Check if anything was retrieved
if($row) {