1
<?php
ob_start();
extract($_REQUEST);
extract($_POST);
session_start();
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
$db=mysql_select_db('murali',$con);


$message = '';
    $error = array();
     $select=mysql_query("select * from registration where username='$_REQUEST[username]'");
	  
   
     
$taken_usernames=mysql_fetch_array($select);

    // main submit logic
    if (@$_REQUEST['action'] == 'register') {
        $resp = check_username($_REQUEST['username']);
        
        if ($resp['ok']) {
            $message = 'All details fine';
        } else {
            $message = 'There was a problem with your registration details';
            $error = $resp;
        }
    } else if (@$_REQUEST['action'] == 'check_username' && isset($_SERVER['HTTP_X_REQUESTED_WITH'])) {
        // means it was requested via Ajax
        echo json_encode(check_username($_REQUEST['username']));
        exit; // only print out the json version of the response
    }
    
    function check_username($username) {
        global $taken_usernames;
        $resp = array();
        $username = trim($username);
        if (!$username) {
            $resp = array('ok' => false, 'msg' => "Please specify a username");
        } else if (!preg_match('/^[a-z0-9\.\-_]+$/', $username)) {
            $resp = array('ok' => false, "msg" => "Your username can only contain alphanumerics and period, dash and underscore (.-_)");
        } else if (in_array($username, $taken_usernames)) {
            $resp = array("ok" => false, "msg" => "The selected username is not available");
        } else {
            $resp = array("ok" => true, "msg" => "This username is free");
        }

        return $resp;        
    }
?>
      <!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>Ajax - PHP example</title>
  
      </head>
 
   
 
      <body>
 
       

      <script language="javascript" type="text/javascript">

      <!--
  
      // Get the HTTP Object
  
      function getHTTPObject(){
 
      if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");

      else if (window.XMLHttpRequest) return new XMLHttpRequest();

      else {

      alert("Your browser does not support AJAX.");

      return null;

      }

      }

       

      // Change the value of the outputText field
 
      function setOutput(){

      if(httpObject.readyState == 4){
  
      document.getElementById('outputText').value = httpObject.responseText;
  
      }
 
       

      }

       
 
      // Implement business logic

      function doWork(){
 
      httpObject = getHTTPObject();
 
      if (httpObject != null) {
  
      httpObject.open("GET", "upperCase.php?inputText="

      +document.getElementById('inputText').value, true);
 
      httpObject.send(null);
 
      httpObject.onreadystatechange = setOutput;
  
      }
 
      }
  
       
 
      var httpObject = null;

       
  
      //-->
 
      </script>

       

      <form name="testForm">

      Input text: <input type="text" onkeyup="doWork();" name="inputText" id="inputText" />

      Output text: <input type="text" name="outputText" id="outputText" />
  
      </form>
 
      </body>
 
      </html>

hello....

i want to do the validations in registration form. but my validation is when the user enters the value in textbox that value automatically cheks that value is already in database or not.


for example..........username textbox is there..now i am entering value first three letter "kal" then comes beside the textbox "username 'kal' is available for you". and next i am entering nextletter "kalp" then comes beside the textbox "kalp is available". plz help me.....any chances to do this task.

4
Contributors
4
Replies
15
Views
7 Years
Discussion Span
Last Post by rony230
0
<?php
ob_start();
extract($_REQUEST);
extract($_POST);
session_start();
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
$db=mysql_select_db('murali',$con);


$message = '';
    $error = array();
     $select=mysql_query("select * from registration where username='$_REQUEST[username]'");
	  
   
     
$taken_usernames=mysql_fetch_array($select);

    // main submit logic
    if (@$_REQUEST['action'] == 'register') {
        $resp = check_username($_REQUEST['username']);
        
        if ($resp['ok']) {
            $message = 'All details fine';
        } else {
            $message = 'There was a problem with your registration details';
            $error = $resp;
        }
    } else if (@$_REQUEST['action'] == 'check_username' && isset($_SERVER['HTTP_X_REQUESTED_WITH'])) {
        // means it was requested via Ajax
        echo json_encode(check_username($_REQUEST['username']));
        exit; // only print out the json version of the response
    }
    
    function check_username($username) {
        global $taken_usernames;
        $resp = array();
        $username = trim($username);
        if (!$username) {
            $resp = array('ok' => false, 'msg' => "Please specify a username");
        } else if (!preg_match('/^[a-z0-9\.\-_]+$/', $username)) {
            $resp = array('ok' => false, "msg" => "Your username can only contain alphanumerics and period, dash and underscore (.-_)");
        } else if (in_array($username, $taken_usernames)) {
            $resp = array("ok" => false, "msg" => "The selected username is not available");
        } else {
            $resp = array("ok" => true, "msg" => "This username is free");
        }

        return $resp;        
    }
?>
      <!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>Ajax - PHP example</title>
  
      </head>
 
   
 
      <body>
 
       

      <script language="javascript" type="text/javascript">

      <!--
  
      // Get the HTTP Object
  
      function getHTTPObject(){
 
      if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");

      else if (window.XMLHttpRequest) return new XMLHttpRequest();

      else {

      alert("Your browser does not support AJAX.");

      return null;

      }

      }

       

      // Change the value of the outputText field
 
      function setOutput(){

      if(httpObject.readyState == 4){
  
      document.getElementById('outputText').value = httpObject.responseText;
  
      }
 
       

      }

       
 
      // Implement business logic

      function doWork(){
 
      httpObject = getHTTPObject();
 
      if (httpObject != null) {
  
      httpObject.open("GET", "upperCase.php?inputText="

      +document.getElementById('inputText').value, true);
 
      httpObject.send(null);
 
      httpObject.onreadystatechange = setOutput;
  
      }
 
      }
  
       
 
      var httpObject = null;

       
  
      //-->
 
      </script>

       

      <form name="testForm">

      Input text: <input type="text" onkeyup="doWork();" name="inputText" id="inputText" />

      Output text: <input type="text" name="outputText" id="outputText" />
  
      </form>
 
      </body>
 
      </html>

hello....

i want to do the validations in registration form. but my validation is when the user enters the value in textbox that value automatically cheks that value is already in database or not.


for example..........username textbox is there..now i am entering value first three letter "kal" then comes beside the textbox "username 'kal' is available for you". and next i am entering nextletter "kalp" then comes beside the textbox "kalp is available". plz help me.....any chances to do this task.

what is ur problem

0

what is ur problem

actually wat i am typeing in the username that will cheked from database...if that name in already database then comes "username already exists". but it is posting values but that is not checking by database. any body help me

-1

i want to make a fully validated form include password and age and with confirm password. please help me to make that form. i try that but i was always fields.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.