How to use a select list to update a mysql db table

How to use a select list to update a mysql db table


OK, I have a web page that has 2 select lists: select1 and select2. Using jQuery I can allow the user to put a selected list item in select1 list to the select2 list. Everything is ok. What I need is one of these possibilities:
  1. When the user clicks the Add button/link on the Attendees list. an event is fired that then gets the option value and puts that value into a MySQL db table. OR
  2. A button is at the bottom of the form and when clicked, some jQuery code is called that iterates over the select2 list option values and inserts them into a MySQL db table.
Here is the code for the page that I now have:


  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/personEventsPages.dwt.php" codeOutsideHTMLIsLocked="false" -->
  3. <head>
  4. <!--
  5. Design by Free CSS Templates
  6. http://www.freecsstemplates.org
  7. Released for free under a Creative Commons Attribution 2.5 License

  8. Name       : Republic  
  9. Description: A two-column, fixed-width design with dark color scheme.
  10. Version    : 1.0
  11. Released   : 20090910

  12. -->
  13. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  14. <link href="css/style.css" rel="stylesheet" type="text/css" media="screen" />
  15. <!-- InstanceBeginEditable name="doctitle" -->
  16. <title>Assign Crews</title>
  17. <script src="javascript/jquery-1.7.2.js" type="text/javascript"></script>
  18. <script type="text/javascript">
  19. $().ready(function() {
  20.  // this was for a clickable link <a href>
  21. $('#add').click(function() {
  22. return !$('#select1 option:selected').remove().appendTo('#select2');
  23. });
  24.  // this one is for a button
  25. $('#addbutton').click(function() {
  26.  return !$('#select1 option:selected').remove().appendTo('#select2');
  27. });
  28.  // this was for a clickable link <a href>
  29. $('#remove').click(function() {
  30. return !$('#select2 option:selected').remove().appendTo('#select1');
  31. });
  32.  // this one is for a button.
  33. $('#removebutton').click(function() {
  34.  return !$('#select2 option:selected').remove().appendTo('#select1');
  35. });
  36. // when a element of the first list is added to the second list
  37. $('#select2').onChange(function() {
  38.  alert("element added to the Assigned List");
  39. });

  40. });
  41. </script>

  42. <!-- InstanceEndEditable -->
  43. <!-- InstanceBeginEditable name="head" -->
  44. <!-- InstanceEndEditable -->
  45. <script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
  46. <link href="SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />

  47. </head>
  48. <body>
  49. <div id="wrapper">
  50.  <div id="header">
  51.  <div id="logo">
  52.  <h1><a href="index.php">Church Events</a></h1>
  53.  </div>
  54.  </div>
  55.  <!-- end #header -->
  56.  <div id="menu">
  57.    <ul id="MenuBar1" class="MenuBarHorizontal">
  58.         <li><a href="#" class="MenuBarItemSubmenu">Persons</a>
  59.           <ul>
  60.             <li><a href="AddAPersonV1.php">Add Persons</a></li>
  61.             <li><a href="viewPersonsV2.php">Persons</a></li>
  62.           </ul>
  63.         </li>
  64.         <li><a class="MenuBarItemSubmenu" href="#">Edit</a>
  65.           <ul>
  66.             <li><a href="viewChurchesV5.php">Churches</a></li>
  67.             <li><a href="viewCitiesV2.php">Cities</a></li>
  68.             <li><a href="viewEvents.php">Events</a></li>
  69.             <li><a href="#">States</a></li>
  70.           </ul>
  71.         </li>
  72. <li><a href="#">Reports</a></li>
  73.    <li><a class="MenuBarItemSubmenu" href="#">Tools</a>
  74.      <ul>
  75.              <li><a href="AssignCrews.php">Assign Crews</a></li>
  76.             <li><a href="#">Clear Crew Members</a></li>
  77.             <li><a href="#">Clear VBS Staff Status</a></li>
  78.   <li><a href="#">Email Clients</a></li>
  79.              <li><a href="#">Export Fields</a></li>
  80.              <li><a href="#">Update Grades</a></li>
  81.          </ul>
  82.      </li>
  83.    <li><a href="#" class="MenuBarItemSubmenu">Crews</a>
  84.      <ul>
  85.               <li><a href="AssignCrews.php">Assign Crews</a></li>
  86.        <li><a href="viewCrewsV2.php">Crew List</a></li>
  87.          </ul>
  88.    </li>
  89.    </ul>
  90. </div>
  91.  <!-- end #menu -->
  92.  <div id="page">
  93.  <div id="page-bgtop">
  94.  <div id="page-bgbtm"><!-- InstanceBeginEditable name="MainContent" -->
  95.    <div id="content">
  96.      <div class="post">
  97.        <h2 class="title"><a href="#">Assign Crews</a></h2>
  98.         <div class="entry">
  99.          <p>
  100.             <table class="dataTable" align="center">
  101.             <tr>
  102.             <td>
  103.             Attendees
  104.             </td>
  105.             <td>
  106.             Assigned
  107.             </td>
  108.             </tr>
  109.             <tr>
  110.             <td>
  111.             <select multiple="multiple" size="10"  id="select1">
  112.             <option value="1">Option 1</option>
  113.             <option value="2">Option 2</option>
  114.             <option value="3">Option 3</option>
  115.             <option value="4">Option 4</option>
  116.             </select>
  117.             <a href="#" id="add">Add >></a>  
  118.             </td>
  119.             <td>
  120.            
  121.             <select multiple="multiple" size="10" id="select2"></select>
  122.             <a href="#" id="remove"><< Remove</a>  
  123.             </td>
  124.             <tr>
  125.             <td>
  126.             <input type="button" value="Add >>" id="addbutton"  />
  127.             </td>
  128.             <td>
  129.             <input type="button" value="<< remove" id="removebutton"  />
  130.             </td>
  131.             </tr>
  132.             </table>
  133.             </p>
  134.         </div>
  135.        </div>
  136.      
  137.      </div>
  138.  <!-- InstanceEndEditable --><!-- end #content -->
  139.    <div id="sidebar">
  140.    <!-- InstanceBeginEditable name="SearchBox" -->
  141.       <ul>
  142.       </ul>
  143.       <!-- InstanceEndEditable -->
  144.      <ul><div style="clear: both;">&nbsp;</div>
  145.    
  146.       <li>
  147.             <li>
  148.               <h2>Persons</h2>
  149.               <ul>
  150.                 <li><a href="AddNewEvent.php">Add New Event</a></li>
  151.                 <li><a href="AddAPersonV1.php">Add New Person</a></li>
  152.                 <li><a href="viewEvents.php">Events List</a></li>
  153.                 <li><a href="viewPersonsV2.php">Person List</a></li>
  154.                 </ul>
  155.               </li>
  156.  <li>
  157.              <h2>Crews</h2>
  158.              <ul>
  159.               <li><a href="AssignCrews.php">Assign Crews</a></li>
  160.              <li><a href="#">Clear Crew Members</a></li>
  161.                 <li><a href="viewCrewsV2.php">Crew List</a></li>
  162.              </ul>
  163.             </li>            
  164.      </ul>
  165.      </div>
  166.  <!-- end #sidebar -->
  167.  <div style="clear: both;">&nbsp;</div> 
  168.  </div>
  169.  </div>
  170.  </div>
  171.  <!-- end #page -->
  172. </div>
  173.  <div id="footer">
  174.  <p>Copyright (c) 2008 Sitename.com. All rights reserved. Design by <a href="http://www.freecsstemplates.org/">Free CSS Templates</a>.</p>
  175.         <p>Copyright (c) 2012 Edgar N. Cohen All rights reserved. Design by Edgar N. Cohen</p>
  176.  </div>
  177.  <!-- end #footer -->
  178. <script type="text/javascript">
  179. var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgDown:"../SpryAssets/SpryMenuBarDownHover.gif", imgRight:"../SpryAssets/SpryMenuBarRightHover.gif"});
  180.     </script>
  181. </body>
  182. <!-- InstanceEnd --></html>