emprit

validasi banyak inputan

Jan 4th, 2013
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.29 KB | None | 0 0
  1. ----------------- index.php ----------------
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  6. <title>Papermashup.com | jQuery PHP Username Checker</title>
  7.  
  8. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js"></script>
  9. <script>
  10. $(document).ready(function(){
  11. $('.username').keyup(username_check);
  12. });
  13.    
  14. function username_check(){ 
  15. var username = $('.username').val();
  16. if(username == "" || username.length < 4){
  17. $('.username').css('border', '3px #CCC solid');
  18. $('.tick').hide();
  19. }else{
  20.  
  21. jQuery.ajax({
  22.    type: "POST",
  23.    url: "check.php",
  24.    data: 'username='+ username,
  25.    cache: false,
  26.    success: function(response){
  27. if(response == 1){
  28.     $('.username').css('border', '3px #C33 solid');
  29.     $('.tick').hide();
  30.     $('.cross').fadeIn();
  31.     }else{
  32.     $('.username').css('border', '3px #090 solid');
  33.     $('.cross').hide();
  34.     $('.tick').fadeIn();
  35.          }
  36.  
  37. }
  38. });
  39. }
  40. }
  41. </script>
  42.  
  43. <style>
  44. .username{
  45.     padding:3px;
  46.     font-size:18px;
  47.     border:3px #CCC solid;
  48. }
  49.  
  50. .tick{display:none}
  51. .cross{display:none}
  52.    
  53.  
  54. </style>
  55. </head>
  56.  
  57. <body>
  58.  
  59. Username: <input name="username[]" rel='1' class="username" id="username" type="text" />
  60. <img class="tick" src="check.gif" width="16" height="16"/>
  61. <img class="cross" src="cross.png" width="16" height="16"/>
  62. <br><br>
  63. Username: <input name="username[]" rel='2' class="username" type="text" />
  64. <img class="tick" src="check.gif" width="16" height="16"/>
  65. <img class="cross" src="cross.png" width="16" height="16"/>
  66.  
  67. </body>
  68. </html>
  69.  
  70. --------------------- check.php----------------
  71. <?php
  72.  // Get the main settings from the array we just loaded
  73.         $host = 'localhost';
  74.         $db = 'karyawan';
  75.         $user = 'root';
  76.         $pass = '';
  77.  
  78.         // Connect to the database
  79.         mysql_connect($host, $user, $pass)or die('koneksi error ');
  80.         mysql_select_db($db) or die('database error');
  81.  
  82. $username = trim(strtolower($_POST['username']));
  83. $username = mysql_escape_string($username);
  84.  
  85. $result =mysql_query("SELECT nama FROM user WHERE nama = '$username' LIMIT 1");
  86. $num = mysql_num_rows($result);
  87. echo $num;
  88. ?>
Advertisement
Add Comment
Please, Sign In to add comment