Good time of day.

There is a users table, when registering a user, there should be a check whether there is a line with the same email column as $ email ( $email == $row['email'] = занято, $email !== $row['email'] = свободно ).

I tried in different ways, but it did not work out. :(

  • @misc, I recommend reading here [this] [1]. To avoid all sorts of there "WHERE email = {$ email}" [1]: hashcode.ru/research/302421/… - VasyOk
  • @VasyOk, yes, already remade with placeholders. - misc

2 answers 2

 $res = $dbh->query("SELECT email FROM users WHERE email = {$email}"); $l_records = $res->fetch(PDO::FETCH_ASSOC); if ($l_records) echo "email занят!"; 

    Here is an option protected from injections and with higher speed due to the issuance limit

     $stmt = $dbh->prepare('SELECT EXISTS(SELECT 1 FROM users WHERE email =:email LIMIT 1)'); $stmt->bindValue(':email', $email, PDO::PARAM_INT); $stmt->execute(); if ($stmt->fetch(PDO::FETCH_NUM)) { // exists }