form validation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kranthi
    New Member
    • Dec 2006
    • 1

    form validation

    form validation using PHP + MYSQL + AJAX
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    So what??

    Ronald :cool:

    Comment

    • ctsasikumar
      New Member
      • Nov 2006
      • 17

      #3
      Hai Using This code Form validation PHP+Mysql+Javas cript
      [php]
      home.php
      <SCRIPT language="javas cript" type="text/javascript">

      // Set path to PHP script
      var phpscript = 'login.php';

      function createRequestOb ject() {

      var req;

      if(window.XMLHt tpRequest){
      // Firefox, Safari, Opera...
      req = new XMLHttpRequest( );
      } else if(window.Activ eXObject) {
      // Internet Explorer 5+
      req = new ActiveXObject(" Microsoft.XMLHT TP");
      } else {
      // There is an error creating the object,
      // just as an old browser is being used.
      alert('There was a problem creating the XMLHttpRequest object');
      }

      return req;

      }

      // Make the XMLHttpRequest object
      var http = createRequestOb ject();


      function sendRequestPost () {

      var user =document.getEl ementById('user name').value;
      var pass = document.getEle mentById('passw ord').value;

      if(user=='')
      {
      alert("Enter the User Name Please");
      document.regfor m.username.focu s();
      return false;
      }
      if(pass=='')
      {
      alert("Enter the Password");
      document.regfor m.password.focu s();
      return false;
      }


      var but= document.getEle mentById('submi t');
      // Open PHP script for requests
      http.open('post ', phpscript);
      http.setRequest Header('Content-Type', 'application/x-www-form-urlencoded');
      http.onreadysta techange = handleResponseP ost;
      http.send('user name='+ user +'&password='+ pass);
      but.value = "please wait...";
      but.disabled = true;
      return true;


      }


      function handleResponseP ost() {
      var but= document.getEle mentById('submi t');
      if(http.readySt ate == 1){
      document.getEle mentById("respo nse").innerHTM L = "Please wait, loading... <img src=images.jpg align=middle>" ;
      } else if(http.readySt ate == 4 && http.status == 200){

      // Text returned from PHP script
      var response = http.responseTe xt;

      if(response) {
      // Update ajaxTest2 content
      document.getEle mentById("respo nse").innerHTM L = response;
      but.value = "Login";
      but.disabled = false;
      //alert(response) ;
      }

      }
      }
      /*function sub(event)
      {

      if(event.keyCod e==13)
      {
      var user = document.getEle mentById('usern ame').value;
      var pass = document.getEle mentById('passw ord').value;
      if(user=="")
      {
      alert("Enter user name");
      return false;
      }
      if(pass=="")
      {

      alert("Enter password");
      return false;
      }
      }
      }*/
      </SCRIPT>
      <META content="MSHTML 6.00.2800.1528" name="GENERATOR "></HEAD>
      <BODY>
      <form method="post" name="regform" action="">
      <div id="all">
      <p>Username:<br >
      <input name="username" type="text" id="username">
      <p>Password:<br >
      <input name="password" type="password" id="password">
      </p>
      <p>
      </div>
      <input name="submit" type="button" value=click onclick="return sendRequestPost ()";>
      </p>
      </form>
      <DIV id="response"> </DIV>
      <BR>
      <br>
      </BODY>
      </HTML>

      Login.php

      <?php
      session_start() ;
      include ('config.php');

      $username = $_POST['username'];
      $password = md5($_POST['password']);
      $querys="SELECT * FROM users WHERE user='". $username ."' AND pass='". $password ."'";
      $query = mysql_query($qu erys);
      $result = mysql_num_rows( $query);
      $row = mysql_fetch_arr ay($query);

      if ($result == 1)
      {
      $_SESSION["user"] = $row["user"];

      echo 'Logged in, '. $row["user"];
      }
      else
      {
      echo 'Wrong username or password.';
      }

      ?>
      [/php]

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        KRANTHI: I'd like to remind you that this is not a code factory!

        The goal of this forum is to have members help other members. But that means that the ones seeking advice must also do what they can to accomodate the ones that want to help them. You should read the Posting Guidelines sometime.

        And a statement like the one you show in your first post in this thread looks more like a command-to-deliver then a request for help. The usual procedure is that you show what you have done yourself to get to a solution, so we can all learn from it. Not by demanding.

        And when other members like to be commandeered around, that is up to them, but I would like to have a civilised exchange of ideas and suggestions. Dumping code without any comment, guidance or explanation is not in that realm.

        Ronald :cool:

        Comment

        Working...