I am trying to check user is exist from data using PHP and Ajax. Using the following codes:
Ajax
$('#btn_check_pc').click(function() {
username = $("#username").val();
$.ajax({
type: 'POST',
url: 'process.php',
data: "username=" + username,
dataType: 'json',
beforeSend: function() { //Do Something
},
success: function(response) {
if (response == 'used') {
console.log("Username Already In Use");
}
}
});
});
PHP
<?php
include_once "includes/get_data.php" ;
$username = $_POST["username"];
//Validating purchase
$checkUserRegistered = mysqli_query($db,"SELECT * FROM users WHERE username = '$username'") or die(mysqli_error($db));
if(!mysqli_num_rows($checkUserRegistered)){
// Do Something
}else{
echo 'used';
}
?>
So When I click the #btn_check_pc
button then the PHP code will response used if the username already exists. I want to show it with console.log("Username Already In Use")
, but it doesn't show. What I am missing here to show console.log()
anyone can help me?