Any help is awesome!

I have two forms. An insert page for the end user and an edit page for the admin. The insert page has several fields that are added by the user with a javascript button (for multiple products of same kind). The edit page is a copy of the submitted form with "accept" and "reject" checkboxes for each product that was entered by the user. The accept and reject are stored in mysql with the product numbers and name entered by the user. I have added a "reason code" for the rejections so that in the users account page they can see what products were rejected and why.

The problem:
The reject code is in a dropdown box for each product that had been submitted. When the values of the dropdowns are submitted only the value of the very first dropdown is passed for EACH of the products.
My Question:
How can I pass the values of EACH dropdown into mysql table? In my mind a foreach makes the most sense or a WHILE - but I get syntax errors up the wazoo.

Here is my code for the edit page:

// updating the boilertable
					$unit_count_new=0;
					foreach( $_POST['boilermodel'] as $boilerkey=>$boilermodel )
					{
						if( isset( $_POST['checkbox_boiler'][$boilerkey] ) )
						{
							$sql = "
								UPDATE
									contractor_boiler_form
								SET
									boiler_model='$boilermodel',
									boiler_serial_no='".$_POST['boilerserial'][$boilerkey]."',
									status='accept' 
								WHERE								
									id=" . $boilerkey
							;
							mysql_query( $sql );
							$unit_count_new+=1;	
						}
						elseif ( isset( $_POST['uncheckbox_boiler'][$boilerkey] ) )
						{
							$boiler_reason=$_POST['dropdownboiler']; 
							$sql = "
								UPDATE
									contractor_boiler_form
								SET
									status='reject',
									reason='$boiler_reason'
								WHERE								
									id=" . $boilerkey
							;
							mysql_query( $sql );
						}
					}

//load reason code
$sql = 'SELECT * FROM reason_code';
  $res = mysql_query($sql) or die(mysql_error());
  while ($rec = mysql_fetch_assoc($res)) $reason[] = $rec;
 // print_r($reason);

//submitted form information is passed here where the reject and accept checkboxes are added
<?			

							$sql="SELECT * from contractor_boiler_form where contractor_form_id=$id"; 

							$result=mysql_query($sql);
							if (!$result)
							{
								echo mysql_error();
							}

							?>

				<table id="boilertable" cellspacing="">



					<? 

					while ($row_boiler=mysql_fetch_assoc($result))
					{

					?>
					<tr>
					<td><label class="desc" id="Boiler_Model1" for="boilermodeac">ACCEPT</label></td>
						<td><label class="desc" id="Boiler_Model1" for="boilermodel1">Boiler Model</label></td>

						<td><label class="desc" id="boilerCP" for="Field30">Boiler CP (Serial) Number</label </td>
					<td><label class="desc" id="Boiler_Model1" for="boilermodere">REJECT</label></td>
						<td><label class="desc" id="Boiler_Model1" for="boilerreas">Reject Reason</label></td>
					</tr>
					<tr>
						<td><input type="checkbox" name="checkbox_boiler[<?=$row_boiler['id']?>]" value="1" unchecked></td>
						<td><input id="boiler1" class="field text medium" name="boilermodel[<?=$row_boiler['id']?>]"  style='width:250px' tabindex="19" type="text" maxlength="255" value="<?=$row_boiler['boiler_model']?>" /> </td>

						<td><input id="boiler1CP"  class="field text medium" name="boilerserial[<?=$row_boiler['id']?>]"  style='width:250px' tabindex="20" type="text" maxlength="255" value="<?=$row_boiler['boiler_serial_no']?>" /> </td>
						<td><input type="checkbox" name="uncheckbox_boiler[<?=$row_boiler['id']?>]" value="0" unchecked></td>
						<td><SELECT name="dropdownboiler<? echo $row_boiler['id']; ?>">
<?  								foreach ($reason as $c)
  								{
   								 if ($c['id'] == $_GET['id'])
      							echo "<OPTION value=\"{$c['id']}\" SELECTED>{$c['description']}</OPTION>\n";
   								 else
     						 echo "<OPTION value=\"{$c['id']}\">{$c['description']}</OPTION>\n";
  								}
  								echo '</SELECT>';?>
  							</td>
							</tr>
							<?

					} // the while loop


					?>


    I personally like to pull my options into an array, count the array and run it through a for loop.

    If I understand you correctly you want to pass the values of ALL of the options?

    if so you'd need to turn your <Select> into a multiple select and change the name of the select to represent an array.

    <select MULTIPLE size='[NumberOfOptions]' name='Options[]'>
    <option value='1'>One</option>
    ect..
    </select>
    

    I hope i'm understanding you correctly.

      Hi there!

      Nope, not a dropdown where you can choose more than one. Its a dropdown per product - so that number always changes.

      See, for each boiler model (which is assigned an id:

      <input id="boiler1" class="field text medium" name="boilermodel[<?=$row_boiler['id']?>]"  style='width:250px' tabindex="19" type="text" maxlength="255" value="<?=$row_boiler['boiler_model']?>" /> </td>

      and its checkbox is checked for accept, its added to mysql table with an "accept" in the field of each product that was accecepted.

      The elseif is for the rejection. Within this elseif I need to run through all the reject checkboxes and if they are checked:

      elseif ( isset( $_POST['uncheckbox_boiler'][$boilerkey] ) )

      I have it adding a "reject" to the table that the product is in. I also need it to go through each dropdown with the rejection reason and update that in the table as well.

      $unit_count_new=0;
      					foreach( $_POST['boilermodel'] as $boilerkey=>$boilermodel )
      					{
      						if( isset( $_POST['checkbox_boiler'][$boilerkey] ) )
      						{
      							$sql = "
      								UPDATE
      									contractor_boiler_form
      								SET
      									boiler_model='$boilermodel',
      									boiler_serial_no='".$_POST['boilerserial'][$boilerkey]."',
      									status='accept' 
      								WHERE								
      									id=" . $boilerkey
      							;
      							mysql_query( $sql );
      							$unit_count_new+=1;	
      						}
      						elseif ( isset( $_POST['uncheckbox_boiler'][$boilerkey] ) )
      						{
      							$boiler_reason=$_POST['dropdownboiler']; 
      							$sql = "
      								UPDATE
      									contractor_boiler_form
      								SET
      									status='reject',
      									reason='$boiler_reason'
      								WHERE								
      									id=" . $boilerkey
      							;
      							mysql_query( $sql );
      						}
      					}
      					
        julietsstars wrote:

        Nope, not a dropdown where you can choose more than one. Its a dropdown per product - so that number always changes.

        The same principle would apply: name the select dropdowns the same way you name the other fields. Don't a multiple-select attribute to the select element, so they'll still behave as normal. You'll still get an array, of course, but you're free to interpret that as an array of selections one per product if you want - exactly as you do for the other fields.

          Write a Reply...