I'm trying to get username availability using ajax
and PDO
from SQL
this works in localhost
but when I host it I get bellow error.
Code:
$(document).ready(function () {
$("#username").keyup(function () {
var username = $(this).val();
if (username.length > 3) {
$("#ucheck").show();
$.ajax({
type: 'POST',
url: './include/namecheck.php',
data: $(this).serialize(),
success: function (data)
{
$("#result").html(data);
$("#ucheck").hide();
}
});
return false;
} else
{
$("#result").html('');
$("#ucheck").hide();
}
});
});
HTML
<input type="text" name="username" value="<?php
if (isset($error)) {
echo filter_input(INPUT_POST, "username");
}
?>" tabindex="1" placeholder="Username" class="form-control" id="username" required autocomplete="off">
PHP
include("$_SERVER[DOCUMENT_ROOT]/include/config.php");
if ($_POST) {
$name = strip_tags($_POST['username']);
$stmt = $conn->prepare("SELECT username FROM members WHERE username=:name");
$stmt->execute(array(':name' => $name));
$count = $stmt->rowCount();
if ($count > 0) {
echo "<small class='text-danger form-text'>Username already taken !</small>";
} else {
echo "<small class='text-success form-text'>Available</small>";
}
}
and the namecheck.php
is located http://safebrowser.tk/include/namecheck.php
and why do I get an error.
Can someone help me sort what wrong in the code?
Thanks in Advance.