4
I’m trying to send from a form
html, a table, with two fields with Array[]
. These two fields are Service and Value, I want to add more than one product on form
, and he insert into different records in my table.
I did so: duplicate the fields in javascript, and send all together by POST.
<input name="valor[]" type="text" id="valor[]" size="6">
In SQL, I’m doing like 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. Duplicated fields are ignored.
They can give me a light there?
Thank you in advance ;)
I don’t know why the foreachs are aligned ... when you put one
;
in foreach he dies right there, in these situations use a delimited block{
and}
and do not use obsolete functions.– rray
didn’t work :/
– Leandro Guilherme
The keys were just a hint, you need to explain why the foreach are aligned, that
$i
also doesn’t make much sense. You need to explain what the purpose of this code is.– rray