I was trying to get values in arrays submitted through form and insert them into database (see my previous post at http://www.phpbuilder.com/board/showthread.php?s=&threadid=10268683). I think I have something but then the arrays behaved strangely. Following is the code. Two arrays are generated after the form is submitted. The array $fid stores values associated with the checked checkoxes. It works fine. The array $total is supposed to store keys and values entered into the input fields. However, I found (using array_values) that array $total stored every key no matter if I entered something or not. Click
here to see it in action. Please help.
<?
if (isset($_POST[submit])) {
//include 'db_connet.php';
if ($_POST[fid]!=0) {
echo "This is fid array<br>";
print_r (array_values($fid));
echo "<p>This is total array<br>";
print_r (array_values($total));
for ($i=0; $i<count($fid); $i++){
$query2 = "insert into photo_order values ('', '$fid[$i]', '$total[$i]', now())";
$query_db2 = mysql_query($query2) or die (mysql_error());
}
}
}
?>
<form method="post" action="testarray.php">
<table>
<tr><td><input type="checkbox" name="fid[]" value="1"></td><td><input type="text" name="total[]" size="1"></td></tr>
<tr><td><input type="checkbox" name="fid[]" value="2"></td><td><input type="text" name="total[]" size="1"></td></tr>
<tr><td><input type="checkbox" name="fid[]" value="3"></td><td><input type="text" name="total[]" size="1"></td></tr>
</table>
<input type="submit" name="submit" value="Send">
</form>