litle ajax + php+ mysql...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AzeriWEB
    New Member
    • Aug 2010
    • 8

    litle ajax + php+ mysql...

    Can somebody write for me a litle script which will help me to create a mod for a sistem

    when somebody will push the button will be update mysql query

    for example when somebody will click on button it will act as
    mysql_query("UP DATE letters SET read=1 WHERE id=$id");
  • johny10151981
    Top Contributor
    • Jan 2010
    • 1059

    #2
    simple ajax example with php

    Comment

    • pradeepkr13
      New Member
      • Aug 2010
      • 43

      #3
      Code:
      <html>
      <head>
      <script>
      var xmlhttp;
      function submitForm(url, str)
      {    
        xmlhttp=GetXmlHttpObject();
        if (xmlhttp==null)
        {
          alert ("Your browser does not support XMLHTTP!");
          return;
        }
        url=url+"?"+str;
        url=url+"&sid="+Math.random();   //to prevent the server from using a cached file
        xmlhttp.onreadystatechange=stateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
      }
      function stateChanged()  //customize this
      {
        if (xmlhttp.readyState==4)
        {
          document.getElementById('fruitresult').innerHTML = xmlhttp.responseText;
        }
      }
      
      function GetXmlHttpObject()
      {
        /*
        try {  xhr = new ActiveXObject('Msxml2.XMLHTTP');   }
        catch (e)
        {
            try {   xhr = new ActiveXObject('Microsoft.XMLHTTP');    }
            catch (e2)
            {
              try {  xhr = new XMLHttpRequest();     }
              catch (e3) {  xhr = false;   }
            }
         }
         */
        if (window.XMLHttpRequest)     // code for IE7+, Firefox, Chrome, Opera, Safari
          return new XMLHttpRequest();
      
        if (window.ActiveXObject)     // code for IE6, IE5
          return new ActiveXObject("Microsoft.XMLHTTP");
      
        return null;
      }
      </script>
      </head>
      
      <body>
      <div id="fruitresult"></div>
      <FORM method="POST" name="ajax" action="">                 
        <INPUT type="BUTTON" value="Submit"  ONCLICK="submitForm('script.php','fruit=1'); return false;">
      </FORM>
      </body>
      </html>
      Put this php in another file and name it as script.php

      Code:
      <?php
      $fruits = Array(1=>"Apple", 2=>"Banan", 3=>"Orange");
      if(isset($_REQUEST['fruit']))
        echo $fruits[$_REQUEST['fruit']];
      else
        echo "Sorry";
      ?>

      Comment

      Working...