Any idea how to tell it if a category hasn't been selected to not do an INPUT for that particular courseID? Right now, for however many courses are listed on the page, it submits all into the database even if I didn't pick a category for it. I need only the courses where i select a category from the dropdown to be submitted.
Here's my code.
And the code that creates my dropdown for Categories
And my Form code:
Here's my code.
Code:
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "category"))
$count = count ($_POST['catid']);
for ($i=0; $i < $count; $i++) {
$corid = $_POST['corid'][$i];
$catid = $_POST['catid'][$i];
mysql_query ("INSERT INTO spec_coursecats (catid, corid)
VALUES ('$catid', '$corid')");
}
And the code that creates my dropdown for Categories
Code:
function addOptions($parent,$depth) {
$sql = $parent>0 ? "select catid,catname from spec_categories where subcatid = $parent ORDER BY catname ASC"
: "select catid,catname from spec_categories where subcatid is null ORDER BY catname ASC" ;
$res = mysql_query($sql);
$indent = str_repeat(' ',$depth); // indent subcats according to depth of call
while (list($id, $desc) = mysql_fetch_row($res)) {
echo "<option value=\"$id\">$indent$desc</option>";
/* the recursive bit */
addOptions($id, $depth+1); // add options for those whose parent is this id
}
And my Form code:
Code:
<form action="<?php echo $editFormAction; ?>" method="POST" name="category" id="category">
<table width="938" border="0" cellpadding="0" cellspacing="0" class="font">
<?php do { ?>
<tr>
<td width="29"><a href="courseedit.php?recordID=<?php echo $row_rs_course['corid']; ?>" class="font">Edit</a> </td>
<td><?php echo $row_rs_course['course_num']; ?> - <?php echo $row_rs_course['ctitle']; ?> </td>
<td align="right">
<select name="catid[]" id="catid[]">
<option value="" selected>Select one</option>
<?php
addOptions(0,0); // call to recursive function
?></select>
<input name="corid[]" type="hidden" id="corid[]" value="<?php echo $row_rs_course['corid']; ?>"> </td>
<td width="55" align="right"><a href="../dbs/admindelete.php?corid=<?php echo $row_rs_course['corid']; ?>" class="delete"> Delete </a> </td>
</tr>
<?php } while ($row_rs_course = mysql_fetch_assoc($rs_course)); ?>
<tr>
<td> </td>
<td> </td>
<td colspan="2" align="left"><input name="categoryset" type="submit" id="categoryset" value="Submit"> <input type="reset" name="Reset" value="Reset">
</td>
</tr></table>
<input type="hidden" name="MM_insert" value="category">
</form>