php - Username Validation Not Working -


i want validate username in database or not not working . add username on database when validate show username available . put code

thats dbconnector.php

<?php  class dbconnector {      var $thequery;     var $link;      function dbconnector(){              // main settings array loaded             $host = 'host';             $db = 'cms';             $user = 'root';             $pass = '';              // connect database             $this->link = mysql_connect($host, $user, $pass);             mysql_select_db($db);             register_shutdown_function(array(&$this, 'close'));          }        //*** function: query, purpose: execute database query ***         function query($query) {              $this->thequery = $query;             return mysql_query($query, $this->link);          }          //*** function: fetcharray, purpose: array of query results ***         function fetcharray($result) {              return mysql_fetch_array($result);          }          //*** function: close, purpose: close connection ***         function close() {              mysql_close($this->link);          }      }      ?> 

and check.php

<?php include("dbconnector.php"); $connector = new dbconnector();  $username = trim(strtolower($_post['username'])); $username = mysql_escape_string($username);  $query = "select username admin username = '$username' limit 1"; $result = $connector->query($query); $num = mysql_num_rows($result);  echo $num; mysql_close();  ?> 

and thats 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> <link href="../style.css" rel="stylesheet" type="text/css" />  <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>    here usernames have been put in database:<br/><br />  hammad, huzaifa , hanzlah<br/><br/>  username: <input name="username" id="username" type="text" /> <img id="tick" src="tick.png" width="16" height="16"/> <img id="cross" src="cross.png" width="16" height="16"/>   </body> </html> 

i think issue html , js.

first add form , give id eg #load put <input...../> in form.

now change jquery.ajax({ url: url +'check.php?'+$("#load").serialize() .

try , sure use js console check if ajax request sent , feedback.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -