I'm trying to send from a form
to html, a table, with two fields with Array[]
. These two fields are Service and Value, I want to add more than one product in form
, and it inserts into different records in my table.
I did this: I duplicate the fields in javascript, and send them all together by POST.
<input name="valor[]" type="text" id="valor[]" size="6">
In SQL, I'm doing this:
$carro=strtoupper($_POST['carro']);
$placa=strtoupper($_POST['placa']);
$cor=strtoupper($_POST['cor']);
$hora=strtoupper($_POST['hora']);
$proprietario=$_POST['proprietario'];
$i = 0;
foreach($_POST["servico"] as $id => $servico);
foreach($_POST["valor"] as $id => $valor);
$telefone=strtoupper($_POST['telefone']);
$buscar=strtoupper($_POST['buscar']);
$obs=strtoupper($_POST['obs']);
$data=strtoupper($_POST['data']);
$ativo=strtoupper($_POST['ativo']);
{
mysql_query("INSERT INTO agenda (carro, placa, cor, hora, proprietario, servico, valor, telefone, buscar, obs, data, ativo) VALUES ('$carro', '$placa', '$cor', '$hora', '$proprietario', '{$_POST['servico'][$i]}', '{$_POST['valor'][$i]}', '$telefone', '$buscar', '$obs', '$data', 'SIM')");
++$i;
};
$i = 0;
However, it saves only the first line. The duplicate fields are ignored.
Can you give me a light there?
Thank you in advance;)