0) { // Username not available $avail[0] = 'no'; $i = 2; // Loop through suggested ones checking them foreach($suggest AS $postfix) { $sql = "SELECT `username` FROM `users` WHERE `username` = '".$username.$postfix."'"; $result = mysql_query($sql); if(mysql_num_rows($result) < 1) { $avail[$i] = $username.$postfix; $i ++; } } $avail[1] = $i - 1; return $avail; } // Username is available return array('yes'); } sajax_init(); // Intialize Sajax //$sajax_debug_mode = 1; //Uncomment to put Sajax in debug mode sajax_export("check_user_exist"); // Register the function sajax_handle_client_request(); // Serve client instances ?>
The following does a gmail style check on the username supplied to see if it is a unqiue username, using the AJAX method.
If not, it makes some suggestions to ones which are available. It uses a development version of Sajax.
View Source (Sajax2.php) | Comments