how can help me about my code ?
i have three page :
index.php :
- <?php
- require_once("includes/funcs.class.php");
- $existUsername = new funcs();
- if(isset($_POST['username']))
- {
- $existUsername->existUsername($_POST['username']);
- }
- ?>
- <!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>Untitled Document</title>
- <script src="js/jquery-1.9.0.min.js" type="text/javascript"></script>
- <script src="js/juser.js" type="text/javascript"></script>
- <link rel="stylesheet" href="style.css" />
- </head>
- <body>
- <div class="divclass">
- <form action="index.php" method="post" id="login">
- Username : <input type="text" name="username" id="username" /><br /><br />
- Password : <input type="text" name="password" id="password" /><br /><br />
- <input type="submit" value="login" id="submitlogin" /><br /><br />
- </form>
- </div>
- </body>
- </html>
funcs.class.php :
- <?php
- require_once("config.class.php");
- class funcs
- {
- protected $_dbconnect;
- protected $_dbusername;
- protected $_dbpassword;
- protected $_dbemail;
- //User's ... Functions ...
- function __construct()
- {
- return config::getInstance();
- }
- function existUsername($dbusername)
- {
- global $dbquery,$dbresult,$dbtable;
- $dbtable = "users";
- $this->_dbusername = $dbusername;
- $this->_dbconnect = config::$_dbconnect;
- $dbquery = $this->_dbconnect->prepare("SELECT * FROM ".$dbtable." WHERE username = :username");
- $dbquery->bindParam(":username",$this->_dbusername);
- $dbquery->execute();
- $dbresult = $dbquery->rowCount();
- if($dbresult == 1)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- }
- ?>
juser.js :
- // JavaScript Document
- $(document).ready(function(e) {
- $('#username').change(function(){
- var existUsername = $('#username').val();
- jQuery.ajax({
- type: "POST",
- url: "index.php",
- data: existUsername,
- cache: false,
- success: function(response)
- {
- if(response)
- {
- alert("Ok . ");
- }
- if(!response)
- {
- alert("No . ");
- }
- }
- });
- });
- });
when i enter the username : saeed � (username is not in the database) -> alert ok .
when i enter the username : admin (username in the datdabase) ->alert ok .
what is the problem ?