Username Validation in Ajax&JS
Download: Scripts
<div class="row">Username: <input type="text" id="uname" name="uname" value="" /> <input type="button" onclick="validate();" value="Check Availability" /><br /> <div id="msg"></div>
validate.php:
<?php $user = strip_tags(trim($_REQUEST['username'])); if(strlen($user) <= 0) { echo json_encode(array('code' => -1, 'result' => 'Invalid username, please try again.' )); die; } $query = "Select * from USERS where username = '$user' "; $available = true; if($available) { echo json_encode(array('code' => 1, 'result' => "Success,username $user is still available" )); die; } else { echo json_encode(array('code' => 0, 'result' => "Sorry but username $user is already taken." )); die; } ?>
No comments:
Post a Comment