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
?>