Hi all and thanks for yours time. I'm using a JS code that check users availablity. The code consists of two pages: index.php and username-check.php. After long attempts, now the code returns "checking...", but then does not return what is required in username-check.php. The writing remains on "checking ...". I've just included the library jquery-1.11.3 min, but doesn't work yet.
What can I do in order to fix this problem?
JS:
$(document).ready(function()
{
$("#name").keyup(function()
{
var name = $(this).val();
if(name.length > 3)
{
$("#result").html('checking...');
$.ajax({
type : 'POST',
url : 'username-check.php',
data : $(this).serialize(),
success : function(data)
{
alert(data);
$("#result").html(data);
},
error : function (j, t) { alert('ajax failed: ' + t); }
});
return false;
}
else
{
$("#result").html('');
}
});
});
HTML
<div class="form-group">
<div class="row" style="margin-left:40%;">Nome: <input class="form-control" type="text" name="name" id="name" placeholder="Inserisci Nome" style="width:40%!important;margin-left:5px;height:20px;font-size:small;" required><div class="disponibile"><span id="result"></span></div></div>
</div>
PHP
$host="localhost";
$user="xxx";
$pass="";
$dbname="xxx";
$myconn = mysql_connect($host, $user, $pass) or die('Errore...');
mysql_select_db($dbname, $myconn) or die('Errore...');
if($_POST)
{
$name = strip_tags($_POST['name']);
$stmt=$dbcon->prepare("SELECT * FROM utenti WHERE nome=:name");
$stmt->execute(array(':name'=>$name));
$count=$stmt->rowCount();
if($count>0)
{
echo "<span style='color:brown;'>Il nome è già attualmente in uso.</span>";
}
else
{
echo "<span style='color:green;'>Il nome è disponibile!
</span>";
}
}