Hello! There is a form: https://jsfiddle.net/pkhyLvcc/

Strange, but on the fidle works on Stack'e not. Well, okay, I think it does not bother much.

The task is as follows: check the <input id='email'/> field and <input id='name'/> for this condition

 <?php if(mysqli_num_rows(mysqli_query("SELECT `users` WHERE `email` = '$email'"))){ echo "<script type='text/javascript'> fail = 'email is already used'; $('#mailErr').text(fail); </script>"; } ?> 

By the way, yes, in the SQL query, the reverse apostrophes were removed.

1 answer 1

You need to check the existence of email in a separate PHP file and after a blur, or another event, send the entered email via ajax to this file, which in turn will return true / false.

  • Ok, I brought in a separate file check. But there is another question - about email. I have a condition in the script that returns fail = "" (the same as false, but I have no error when fail is an empty string) is an else condition. What query in else if I write that would be equivalent to mysqli_num_rows (mysqli_query)? - Eugen Eray
  • Did not quite understand the question. In the check file, you need to write an if check (mysqli_num_rows (mysqli_query) == 0) {echo 'true'; } else {echo 'false'; } In the ajax request, check the value: $ .ajax ({... success: function (res) {if (res! = 'True') {alert ('This email is already registered');}}}) - Alexandr Kiseloy