I'm using ajax to check if a username is taken. If the username is taken it returns false to the form submit function. I'm using MySQL.
index.php
$("#register-form").submit(function(){
var un = $("#un").val();
$.ajax({
type: "GET",
url: "user_check.php",
dataType: "html",
data: {un: un},
success: function(data){
}
});
});
user_check.php
$db = mysqli_connect("localhost","root","","webcap");
$user = $_POST['un'];
$query = mysqli_query($db,"SELECT * FROM users WHERE username='$un'");
$count = mysqli_num_rows($query);
echo $count;
How I return false to the register form submit function if data is 1 or true if it's 0? Is there an easier way to do this?