Submit PHP form to MYSQL database using AJAX -


i have php page displays records mysql database in table. want able edit record in table cell clicking on cell. process picture go this:

1) onclick() event on table cell triggers ajaxfunction()
2) ajaxfunction() sends cell data php page querys database , displays drop down list of options.
3) user selects option drop down list
4) onchange() event submits form database
5) table cell or page refreshed show current table cell data. (not in existing code)

right i've got 2 php pages ac_sched.php , modsched.php.

here structure of each page:

ac_sched.php:

  • php created table displaying mysql records
  • ajaxfunction query database available cell options

modsched.php:

  • php code select available cell options database , create dropdown.
  • php code update database selected option dropdown.

here relevant sections of code each page:

ac_sched.php:  <script> function acschedquery(reg)     {     if (window.xmlhttprequest)         {// code ie7+, firefox, chrome, opera, safari         xmlhttp=new xmlhttprequest();         }     xmlhttp.onreadystatechange=function()         {         if (xmlhttp.readystate==4 && xmlhttp.status==200)             {             document.getelementbyid(reg).innerhtml=xmlhttp.responsetext;             }         }     xmlhttp.open("get","../process/modsched.php?modsched_reg="+reg,true);     xmlhttp.send();     } </script>  <table>  <tr> <td id="abc-day-3" onclick="acschedquery(this.id)"></td> </tr>  ......rest of table here...... </table>   modsched.php:  // request options database   if(isset($_get['modsched_reg']))     {     $modsched_array = explode("-",$_get["modsched_reg"]);     $modsched_reg = $modsched_array[0];     $modsched_day = $modsched_array[1];     $modsched_id = $modsched_array[2];      $sql4 = ("select * aircraft_sched_options schedopt_id != 0");      if(!$result_sql4 = $mysqli->query($sql4))         {         echo querycheck("getting schedule options ","from aircraft sched options",$mysqli);         }     ?>     <form action="../process/modsched.php" method="post">// did try: action=""         <table cellpadding="0" cellspacing="0" border="0">          <tr>         <td>     <?php     echo "<select name=\"modsched_id\">";      while($schedopt = $result_sql4->fetch_assoc())         {         echo "<option value=\"" . $modsched_reg . "-" . $modsched_day .  "-" . $schedopt['schedopt_id'] . "\" onchange=\"formsubmit(this.form)\"";         if($schedopt['schedopt_id'] == $modsched_id)             {             echo " selected=\"selected\"";             }         echo ">" . $schedopt['schedopt_name'] . "</option>";         }      echo "</select>";     ?>         </td>         </tr>          </table>     </form>     <?php     }    // submit selected option database if(isset($_post['modsched_id']))     {     $modsched_array = explode("-",$_post["modsched_id"]);     $modsched_reg = $modsched_array[0];     $modsched_day = $modsched_array[1];     $modsched_id = $modsched_array[1];      $sql4 = ("update aircraft_status set $modsched_day = $modsched_id ac_reg = $modsched_reg");      if(!$result_sql4 = $mysqli->query($sql4))         {         echo querycheck("updating aircraft schedule ","into aircraft sched",$mysqli);         }      } 

i know lot of code, think it's needed in order show whole story.
think if takes @ code structure have, tell me if i'm on right track or not, big help. here questions have regarding code:

1) form submit changes in right place? - had second ajaxfunction() submit selected option form submit page. didn't work, have been code , not structure itself.

2) should have form submit code on own page?

i have started use ajax week, way off mark here. appreciated.

you can implement framework cakephp or symphony, framework can in process learn language , practices.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -