I was looking around for ways to make it but I only seen it being done with ajax and no PHP explanation/usage at all.
What do I mean?: I want the username check validation to be done at real time, means that if the user inserts a username that already exists, it will immediately show an error message.
Example of what I mean:
register.php
if(isset($_POST["reg"]))
{
$name = $_POST["name"];
$query = mysqli_query($link, "SELECT * FROM `users` WHERE `name`='$name');
if(mysqli_num_rows($query))
{
...
}
else
{
...
}
}
form.html
<head>
<script>
$(document).ready(function(){
$("#error").hide();
});
</script>
</head>
<div id="error">
Username exists.
</div>
<form action="register.php" method="post">
Name: <input type="text" name="name" />
<input type="submit" name="reg" />
</form>
(Only the relevant code has been copied for comfort, the other required tags exist in the original code)
I want the #error div to show whenever the username exists (without reloading the page) and to hide whenever everything is okay, and disallow the user to submit the form, I'm not sure how can I do it efficiently.
Thanks in advance.