jQuery UniqueField plugin is ajax based tool who check availability of usernames, email addresses or etc. Use in your register, sign up or other forms.
<script type="text/javascript">
$(function(){
$('#username_1').uniqueField({
url: 'ajax.php',
baseId: 'exam_x'
});
});
</script>
<script type="text/javascript">
$(function(){
$('#username_2').uniqueField({
url: 'ajax.php',
baseId: 'exam_y'
});
$('#email').uniqueField({
url: 'ajax.php',
baseId: 'exam_z'
});
});
</script>
<script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript" src="js/jquery.uniquefield.js"></script> <link type="text/css" rel="stylesheet" href="css/jquery.uniquefield.css" />ajax.php
<?php
# Open a connection to a MySQL Server
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
# Select a MySQL database
$db_selected = mysql_select_db('foo', $link);
if (!$db_selected) {
die ('Can\'t use foo : ' . mysql_error());
}
if (isset($_POST['field']) && isset($_POST['value'])){
$field = mysql_real_escape_string($_POST['field']);
$value = mysql_real_escape_string($_POST['value']);
$result = mysql_query("SELECT COUNT() AS `count` FROM `table_users`
WHERE `$field` = '$value' LIMIT 1", $link) or die(mysql_error());
if (mysql_fetch_object($result)->count == 0) {
# Value is available
echo 1;
} else {
# Value is already in use
echo 0;
}
}
# Close MySQL connection
mysql_close($link);
?>
jQuery UniqueField plugin is currently available for use in all personal or commercial projects under both MIT and GPL licenses. This means that you can choose the license that best suits your project, and use it accordingly.
Dimitar Ivanov
info@bulgaria-web-developers.com
www.bulgaria-web-developers.com
www.bulgaria-web-developers.com/blog