Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----------------- index.php ----------------
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
- <title>Papermashup.com | jQuery PHP Username Checker</title>
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js"></script>
- <script>
- $(document).ready(function(){
- $('.username').keyup(username_check);
- });
- function username_check(){
- var username = $('.username').val();
- if(username == "" || username.length < 4){
- $('.username').css('border', '3px #CCC solid');
- $('.tick').hide();
- }else{
- jQuery.ajax({
- type: "POST",
- url: "check.php",
- data: 'username='+ username,
- cache: false,
- success: function(response){
- if(response == 1){
- $('.username').css('border', '3px #C33 solid');
- $('.tick').hide();
- $('.cross').fadeIn();
- }else{
- $('.username').css('border', '3px #090 solid');
- $('.cross').hide();
- $('.tick').fadeIn();
- }
- }
- });
- }
- }
- </script>
- <style>
- .username{
- padding:3px;
- font-size:18px;
- border:3px #CCC solid;
- }
- .tick{display:none}
- .cross{display:none}
- </style>
- </head>
- <body>
- Username: <input name="username[]" rel='1' class="username" id="username" type="text" />
- <img class="tick" src="check.gif" width="16" height="16"/>
- <img class="cross" src="cross.png" width="16" height="16"/>
- <br><br>
- Username: <input name="username[]" rel='2' class="username" type="text" />
- <img class="tick" src="check.gif" width="16" height="16"/>
- <img class="cross" src="cross.png" width="16" height="16"/>
- </body>
- </html>
- --------------------- check.php----------------
- <?php
- // Get the main settings from the array we just loaded
- $host = 'localhost';
- $db = 'karyawan';
- $user = 'root';
- $pass = '';
- // Connect to the database
- mysql_connect($host, $user, $pass)or die('koneksi error ');
- mysql_select_db($db) or die('database error');
- $username = trim(strtolower($_POST['username']));
- $username = mysql_escape_string($username);
- $result =mysql_query("SELECT nama FROM user WHERE nama = '$username' LIMIT 1");
- $num = mysql_num_rows($result);
- echo $num;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment