Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple submit help needed. 1

Status
Not open for further replies.

VAMick

Programmer
Nov 18, 2005
64
US
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.

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('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',$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>&nbsp;</td>
          <td><?php echo $row_rs_course['course_num']; ?> - <?php echo $row_rs_course['ctitle']; ?>&nbsp;</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']; ?>">          &nbsp;</td>
          <td width="55" align="right"><a href="../dbs/admindelete.php?corid=<?php echo $row_rs_course['corid']; ?>" class="delete"> &nbsp;&nbsp;Delete&nbsp;&nbsp; </a>&nbsp;</td>
        </tr>
        <?php } while ($row_rs_course = mysql_fetch_assoc($rs_course)); ?>
    <tr>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
		<td colspan="2" align="left"><input name="categoryset" type="submit" id="categoryset" value="Submit">&nbsp;<input type="reset" name="Reset" value="Reset">
		  </td>
    </tr></table>
      
        <input type="hidden" name="MM_insert" value="category">
    </form>
 
what does the QUERY_STRING look like if you echo it to the screen, maybe you could check for empties:

if(!empty($_POST['corid'][$i]))
{
$corid = $_POST['corid'][$i];
$catid = $_POST['catid'][$i];
mysql_query ("INSERT INTO spec_coursecats (catid, corid)
VALUES ('$catid', '$corid')");
}

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
WONDERFUL!!!! Only thing I changed was for it to check the catid for empty instead, and that works beautifully!!!

Thanks much....Gold stars for you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top