By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,946 Members | 773 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,946 IT Pros & Developers. It's quick & easy.

I want to use input from multiple drop downs and input the values into an sql table.

P: 4
I have created a php page that is populated with information from the sql table module. From here i rank the modules using a drop down based on the amount of modules displayed. How do i go about saving these multiple value drops in conjunction with the student id and moduleID

this below is my code for the student menu
Expand|Select|Wrap|Line Numbers
  1. <html>
  2.     <head>
  3.         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  4.         <title>Module Selector</title>
  5.         <style>
  6.             tr {background-color:lightblue;}
  7.             td {text-align:center;}
  8.     </style>
  9.     </head>
  10.     <body>
  11.     <h1> Rate The Modules in Order of Prefrence With 1 Being The Highest</h1> 
  12.     <form action= "<?php echo $_SERVER['PHP_SELF']; ?>"  method="post">
  13.         <?php
  14.  
  15.             require_once "./includes/connection.inc.php";
  16.             $conn = dbConnect();
  17.             //echo 'connected';
  18.             //Ruth Gammack - prepare statement to count the number of modules available for student
  19.                 $sel = $conn->prepare('select count(*) from module student where student.courseID = courseID');
  20.  
  21.                 $sql = "SELECT * FROM module student WHERE student.courseID = courseID";
  22.                 $stmt = $conn->prepare($sql);
  23.  
  24.             try {
  25.                 $stmt->execute();
  26.                 $sel->execute();
  27.  
  28.                 $results = $stmt->fetchAll();
  29.                 $count = $sel->fetchColumn();
  30.  
  31.                 if (!$results){ // check we have some results
  32.                     echo "No modules Available at this time please try again later <br />";
  33.                 }
  34.                 else{    //generate table of modules
  35.                     print "<table>\n";
  36.                     echo "<th>ModuleID</th><th>Name</th><th>Description</th><th>Lecturer</th><th>Ranking</th>";   
  37.                     {
  38.                     foreach ($results as $row){
  39.  
  40.                         echo "<tr>";
  41.                         echo "<td>".$row["moduleID"]."</td>";
  42.                         echo "<td>".$row["ModuleName"]."</td>";
  43.                         echo "<td>".$row["ModuleDesc"]."</td>";
  44.                         echo "<td>".$row["LecturerID"]."</td>";
  45.                         //Display a dropdown for each module selected for the user from the database
  46.                            echo "<td><select name='modRankDropdown'>";
  47.                         //Ruth Gammack- using a temp count = to the count returned from the database
  48.                         $tempcount = $count;
  49.                             //while the count is more than 0 echo the temp count in the option box and the decrement by one
  50.                             while ($tempcount > 0){
  51.                                 echo "<option value='".$tempcount."'>".$tempcount."</option>";
  52.                                 $tempcount--;
  53.                             }
  54.                         echo"</select></td>";
  55.                     }
  56.                   }
  57.                     echo "</table>";
  58.  
  59.                     echo "<br> Confirm Modules: <INPUT TYPE = 'Submit' Name = 'Submit' VALUE = 'Submit'>";
  60.  
  61.                 }
  62.             } catch ( PDOException $e ) {
  63.                 echo "Query failed: " . $e->getMessage();
  64.             }
  65.             // close database connection
  66.             dbClose($conn);
  67.        ?>
  68.         </form>
  69.         <a href="choices.php?action=viewChoices">View Choices</a>
  70.     </body>
  71. </html>
  72.  
  73.  
  74.  
Dec 5 '11 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.