I tried to insert multiple rows from one form using checkboxes, include take values from input box, all of them has the structure:
<input id="Valor" type="text" name="Valor[]" value="<?php echo $row2["Valor"]; ?>" />
and the checkbox is like:
<input type="checkbox" name="Pago[]" id="Pago" value="<?php echo $row2["IdSolicitudTarjeta"]; ?>" />
But when I’ll send the form at ‘insertmultiple.php’ I use the following code but only shows 2 results. Don’t matter how many times I tried show the rest, don’t works:
foreach($_POST['Pago'] as key => $val) {
$Producto = $_POST['Producto'][$key];
$FormaPago = $_POST['FormaPago'][$key];
$FechaConsignacion = $_POST['FechaConsignacion'][$key];
$Valor = $_POST['Valor'][$key];
$Detalle = $_POST['Detalle'][$key];
$FechaRegistrar = $_POST['FechaRegistrar'][$key];
echo $Pago." -- ".$FechaConsignacion." -- ".$Producto." -- ";
echo $FormaPago." -- ".$Valor." -- ".$Detalle." -- ";
echo $FechaRegistrar."<br>";
}
please help! 🙁
First thing:
not
keybut$keyI dont see any SQL code though.
ADDENDUM
Hm… it seems like a really messy way to insert things into database. As Cyclone noticed you do not purify your input prior to inserting the date. This is wrong but its a story for another post :p
Besides consider one thing:
Are you sure you want to use
and not:
You seem to store some id in those checkboxes… otherwise you may have a scenario like:
So I blieve that
$_POST['Pago']will have only 2 fields 1 and 4… but their key will be 1 and 2 as inactive checkboxes will not have value and will not end-up in the array. I may be wrong though… shame to admit I do not remember how it works precisely O.o