8
I need to save several input that contains the same "name", but the problem is that it only saves one single result for several.
Example:
<form method="post" action="guardar.php">
<input type="hidden" name="produto" value="teste1">
<input type="hidden" name="produto" value="teste2">
<input type="hidden" name="produto" value="teste3">
<input type="hidden" name="produto" value="teste4">
<input type="hidden" name="produto" value="teste5">
<input type="submit" value="enviar">
</form>
PHP:
$produtos = $_POST["produto"];
mysql_query("INSERT INTO produtos (produtos) VALUES ("$produtos"") or die("Erro query.<br>Mensagem do servidor: ".mysql_error());
But in the bank comes only:
teste1
How I would save all input values if they have the same name?
Updating:
Problem solved by adding [] as name of input, turning it into a array and then treat them with foreach.
'Cause you don’t change the name, in this particular case I’m not seeing any reason to use the same name.
– Maniero
the problem is that these
inputare automatically generated with each user click on a value on the site. if it selects 3 products? would have to be ainputproducts for each, wanted to try another way besides generating ainputwith anamedifferent for each item.– Cassiano José
If you name it
produtos[]to their inputs, I believe they will be sent to PHP as an array.– mgibsonbr