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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ruth Gammack
    New Member
    • Dec 2011
    • 4

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

    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
    Code:
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>Module Selector</title>
            <style>
                tr {background-color:lightblue;}
                td {text-align:center;}
    	</style>
        </head>
        <body>
    	<h1> Rate The Modules in Order of Prefrence With 1 Being The Highest</h1> 
    	<form action= "<?php echo $_SERVER['PHP_SELF']; ?>"  method="post">
            <?php
            
                require_once "./includes/connection.inc.php";
                $conn = dbConnect();
                //echo 'connected';
    			//Ruth Gammack - prepare statement to count the number of modules available for student
    				$sel = $conn->prepare('select count(*) from module student where student.courseID = courseID');
    				
                    $sql = "SELECT * FROM module student WHERE student.courseID = courseID";
                    $stmt = $conn->prepare($sql);
                   
                try {
                    $stmt->execute();
                    $sel->execute();
                   
                    $results = $stmt->fetchAll();
                    $count = $sel->fetchColumn();
                    
                    if (!$results){ // check we have some results
                        echo "No modules Available at this time please try again later <br />";
                    }
                    else{	//generate table of modules
                        print "<table>\n";
                        echo "<th>ModuleID</th><th>Name</th><th>Description</th><th>Lecturer</th><th>Ranking</th>";   
                        {
                        foreach ($results as $row){
                        	
                            echo "<tr>";
                            echo "<td>".$row["moduleID"]."</td>";
                            echo "<td>".$row["ModuleName"]."</td>";
                            echo "<td>".$row["ModuleDesc"]."</td>";
                            echo "<td>".$row["LecturerID"]."</td>";
    						//Display a dropdown for each module selected for the user from the database
                           	echo "<td><select name='modRankDropdown'>";
    						//Ruth Gammack- using a temp count = to the count returned from the database
    						$tempcount = $count;
    							//while the count is more than 0 echo the temp count in the option box and the decrement by one
    							while ($tempcount > 0){
    								echo "<option value='".$tempcount."'>".$tempcount."</option>";
    								$tempcount--;
    							}
    						echo"</select></td>";
                        }
                      }
                        echo "</table>";
    					
    					echo "<br> Confirm Modules: <INPUT TYPE = 'Submit' Name = 'Submit' VALUE = 'Submit'>";
    				
                    }
                } catch ( PDOException $e ) {
                    echo "Query failed: " . $e->getMessage();
                }
                // close database connection
                dbClose($conn);
           ?>
            </form>
            <a href="choices.php?action=viewChoices">View Choices</a>
        </body>
    </html>
Working...