HELP NEEDED - Posting array values from a form
Posted: Wed Aug 11, 2004 9:07 am
Can someone help me? I am sure I am overlooking something simple, but it is eluding me right now. I have a script that captures vehicle information and places it into a form for updating car wash mileage and car wash dates. On submit, I want the script to process each post and enter the data into the DB. I am testing the script with the PHP functions LIST and EACH. Here is the HTML form (shortened for this forum):
Here is the code that processes this submit (in test form to track output):
$message is only used to track var values passed to the script. When the form submits, I get an a error that says $_POST['wash_date'] is not an array. But when I print $_POST['wash_date'] to the screen, the value shows up as Array. The same holds true for $_POST['wash_miles']. Can someone please help out with this one. I am stumped.
Thanks in advance for all your help.
Code: Select all
<form method="POST" action="/admin/cp_carwash.php">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td height="25" class="cat"><span class="cattitle">Plate</span></td>
<td height="25" class="cat"><span class="cattitle">Vehicle</span></td>
<td height="25" class="cat"><span class="cattitle">Wash Date</span></td>
<td height="25" class="cat"><span class="cattitle">Mileage</span></td>
</tr>
<tr>
<td><span class="gensmall">5088-01B</span></td>
<td><span class="gensmall">5TEGN92N03Z187273 - 2003 Toyota Tacoma PreRunner Dbl Cab V6</span></td>
<td><input type="text" size="12" name="wash_dateї114]" value="6/9/2004" /></td>
<td><input type="text" size="12" name="wash_milesї114]" value="9230" /></td>
</tr>
<tr>
<td class="row1"><span class="gensmall">5088-02B</span></td>
<td class="row1"><span class="gensmall">5TEVL52N63Z193651 - 2003 Toyota Tacoma 4X2 Ext Cab Auto</span></td>
<td class="row1"><input type="text" size="12" name="wash_dateї208]" value="6/2/2004" /></td>
<td class="row1"><input type="text" size="12" name="wash_milesї208]" value="13280" /></td>
</tr>
<tr>
<td><span class="gensmall">5088-17B</span></td>
<td><span class="gensmall">5TEHN72N83Z180516 - 2003 Toyota Tacoma 4X4 Dbl Cab Auto V6</span></td>
<td><input type="text" size="12" name="wash_dateї190]" value="5/26/2004" /></td>
<td><input type="text" size="12" name="wash_milesї190]" value="7765" /></td>
</tr>
<tr>
<td colspan="4" align="center" valign="middle">
<input type="hidden" name="submit_form" value="true" />
<input type="submit" name="send_wash_data" value="Submit Wash Data Changes" />
</td>
</tr>
</table>
</form>Code: Select all
<?php
if ( isset($_POST['submit_form']) && $_POST['submit_form'] == 'true')
{
// how about we make arrays out of them first
$wd_array = $_POST['wash_date'];
// Here comes the data
// dates first
$message = 'Preparing the insert...';
if (is_array($wd_array))
{
$message .= '<br />wash_date is an array...';
while (list($car_id, $wash_date) = each($_POST['wash_date']))
{
if ($wash_date == '')
{
$wash_date = 0;
}
else
{
strtotime($wash_date);
}
$message .= '<br />Vehicle: ' . $car_id . ' was updated to ' . $wash_date . '...';
}
$message .= '<br /><br />Now for the mileage...';
while (list($car_id, $wash_miles) = each($_POST['wash_miles']))
{
$message .= '<br />Vehicle: ' . $car_id . ' was updated to mileage ' . $wash_miles . '...';
}
}
else
{
$message .= '<br />Wash_date is not an array, here is: ' . $_POST['wash_date'];
}
$message .= '<br />post_wash_date = ' . $_POST['wash_date'];
$message .= '<br />post_wash_miles = ' . $_POST['wash_miles'];
}
?>Thanks in advance for all your help.