It worked! Now...
I have the following (and please don't tear me apart for bad coding :o - using DW) part of a form that generates a list of PROJECTS. Each has a hidden form element project ID. There is a dropdown in front of each title to select their LEVEL if I assign them. The default is NOT ASSIGNED value NULL.
<?php do { ?>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr <?php echo " style=\"background-color:$color\"";?>>
<td width="26%" class="pad_cell">
<select name="level" id="level">
<option value="NULL" selected>Not Assigned</option>
<option value="1">Primary</option>
<option value="2">Secondary</option>
<option value="3">Assigned</option>
</select>
</td>
<td width="74%" class="pad_cell"> <?php echo $row_projects['initiative']; ?><input name="project[]" type="hidden" id="project[]" value="<?php echo $row_projects['id']; ?>">
</td>
</tr>
<?php if ($color == $color1) { $color = $color2; } else { $color = $color1; } ?>
</table>
<?php } while ($row_projects = mysql_fetch_assoc($projects)); ?>
When I submit the user, each item in the PROJECTS_ASSIGNED table gets filled. There are 27 PROJECTS, and they all get a unique AUTO INCREMENT ID, then the USER_ID is filled (with the mysql_insert_id value) and all LEVEL fields are filled with NULL. How do I pass only the ones that were chosen as assigned (Not the unselected ones set to NOT ASSIGNED = NULL) and disregard the rest. I know the code doesn't work, but here's where I'm stuck:
if(isset($_POST['project'])) {
$project = $_POST['project'];
$level = $_POST['level'];
$number = count($project);
for ($i=0; $i<$number; $i++)
{
echo $i.' '.$level.'<br />';
$selected_project = $project[$i];
$query = "INSERT INTO projects_assigned (project_id, user_id, level) VALUES ('$selected_project', '$user_id', '$level')";
mysql_query($query) or die(mysql_error());
}
}