I’m hoping this is something small. After combing through this for a couple hours and trying all sorts of variations I’ve decided to let the pros have a crack at it.
I’ve got a page setup to administer a database easily. Basically just to update a row or delete it. For each row I’ve got a checkbox to update the row, check box to delete, three columns of info from database and then two columns with dropdown boxes to change values.
The issue is that no matter what values I choose from the dropdown, it always posts the same values. Using print_r($_POST) I can see that it’s actually returning the wrong value. Without further ado, the code:
This is at the top of my page (the form post to itself):
if(isset($_POST['checkbox'])){
$product = $_POST['product_choice'];
$status = $_POST['status_choice'];
$checkbox = $_POST['checkbox'];
if(isset($_POST['update'])){
$update = $_POST["update"];
}
$id = "('" . implode( "','", $checkbox ) . "');" ;
$sql="UPDATE test_orders SET product='$product',status = '$status' WHERE ordNum IN $id" ;
$result = mysql_query($sql) or die(mysql_error());
}
And the form:
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><form name="frmactive" method="post" action="">
<table width="400" border="0" cellpadding="3" cellspacing="1">
<!--BUTTONS-->
<tr>
<td colspan="6"><input name="update" type="submit" id="update" value="Upate" />
<input name="delete" type="submit" id="delete" value="Delete" /></td>
</tr>
<tr>
<td> </td>
<td colspan="5"><strong>Update multiple rows in mysql with checkbox</strong> </td>
</tr>
<tr>
<td style="background: #ddd; padding:5px; border-left:1px solid #ccc; border-top:1px solid #ccc;">Update?</td>
<td style="background: #ddd; padding:5px; border-left:1px solid #ccc; border-top:1px solid #ccc;">Delete?</td>
<td style="background: #ddd; padding:5px; border-left:1px solid #ccc; border-top:1px solid #ccc;">Order #</td>
<td style="background: #ddd; padding:5px; border-left:1px solid #ccc; border-top:1px solid #ccc;">Name</td>
<td style="background: #ddd; padding:5px; border-left:1px solid #ccc; border-top:1px solid #ccc;">Job Name</td>
<td style="background: #ddd; padding:5px; border-left:1px solid #ccc; border-top:1px solid #ccc;">Product</td>
<td style="background: #ddd; padding:5px; border-left:1px solid #ccc; border-top:1px solid #ccc;">Status</td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['ordNum']; ?>"></td>
<td bgcolor="#FF0000" align="center"><input type="checkbox" name="delete[]" id="delete[]" value="<? echo $rows['ordNum']; ?>" /></td>
<td><? echo $rows['ordNum']; ?></td>
<td><? echo $rows['name']; ?></td>
<td><? echo $rows['OrderDesc']; ?></td>
<td>
<select name="product_choice" id="product" style="font-size:10px;">
<option value="<? echo $rows['product']; ?>" selected="selected"><? echo $rows['product']; ?>
</option>
<option value="Color Correction"> Color Correction </option>
<option value="Basic retouch"> Basic retouch </option>
<option value="Extensive Retouch"> Extensive Retouch </option>
<option value="Signature Work"> Signature Work </option>
<option value="Signature Oil"> Signature Oil </option>
<option value="Web Design"> Web Design </option>
<option value="Print Design"> Print Design </option>
<option value="Other"> Other </option>
</select>
</td>
<td>
<select name="status_choice" id="status" style="font-size:10px;">
<option value="<? echo $rows['status']; ?>" selected="selected"><? echo $rows['status']; ?></option>
<option value="Order Received"> Order Received </option>
<option value="in the works"> in the works </option>
<option value="waiting to upload"> waiting to upload </option>
<option value="uploading"> uploading </option>
<option value="ON HOLD"> ON HOLD </option>
<option value="awaiting decision"> awaiting decision </option>
<option value="proof sent"> proof sent </option>
<option value="next invoice"> next invoice </option>
<option value="waiting images/order"> waiting images/order </option>
<option value="invoiced"> invoiced </option>
<option value="complete"> complete </option>
<option value="paid"> paid </option>
<option value="making changes"> making changes </option>
</select>
</td>
</tr>
<?php
}
?>
<tr>
<td colspan="6" align="center"> </td>
</tr>
</table>
</form>
</td>
</tr>
</table>
This is the result of print_r($_POST); no matter what options I choose in the dropdowns. the [product_choice] and [status_choice] are always the same.
Array ( [update] => Upate [checkbox] => Array ( [0] => 113 ) [product_choice] => Extensive Retouch [status_choice] => Order Received )
thanks for any help.
****SOLVED*********
Got some help from a friend, Working good is below
opening foreach loop:
And the Dropdown boxes: