using multiple list menu and checkbox php

Am retrieving some data from the DB and am allowing users to make multiple selection via check box and also selecting a level for each selected check box. when saving, i only get to see the selected check boxes in the DB but not the level selected.

Code for making selection

include ('mysql_connect.php');

$sql = mysql_query("SELECT * FROM competency WHERE department = '$department'");

while($row = mysql_fetch_array($sql))
echo "<tr>";
echo "<td>";
echo"<input type='checkbox' name='comp[]' value= ".$row['id']." /> ".$row['competency']." <br /> </td>";
echo"<td> <select name='level[]'value= ".$row['id']." >
				  <option>level 1</option> 
				  <option>level 2</option> 
				  <option>level 3</option> 
				  <option>level 4</option>
				  <option>level 5</option>  </select>                 </td> ";

echo "</tr>";

<input name="submit" type="submit" value="submit" />
echo" </table>";


Code for saving into the DB

$id = $_SESSION['user_id'];

$hobb = $_POST['comp'];
$level  = $_POST['level'];
include ('mysql_connect.php');

 $N = count($hobb);

        for($i=0; $i < $N; $i++)
			$var2 =  $level[$i];
            //include ('connect.php');
			include ('mysql_connect.php');
            $table = "INSERT INTO competency_result (user_id,competency_id,level) ".
                     "VALUES ('$id', '$var1', '$var2')";
            mysql_query($table) or die(mysql_error());
            $inserted_fid = mysql_insert_id();

Source: mysql

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.