-4
I must create 20 inputs that when filled out should show what was typed in them right below, using arrays and foreach, here is the code below:
function repeteInput(){
for($i = 1; $i <= 20; $i++){
echo '<form action="repeteInput.php" method="post">';
echo 'Digite um número aqui ('.$i.')<input type="text" name "produto[]"><br>';
}
echo '<input type="submit" value="Enviar"></form>';
$produtos = $_POST['produto'];
foreach ($produtos as $produto){
echo $produto."<br>";
}
}
echo repeteInput();
I already checked the code, and it looks exactly like the one I copied in my notebook, which worked on another PC. Even so, it shows this error after the page:
Notice: Undefined index: produto in C:\xampp\htdocs\24.04.2017\repeteInput.php on line 8
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\24.04.2017\repeteInput.php on line 9
First of all, put the
<form action="repeteInput.php" method="post">
out of the loop for, for various tags<form>
are being opened and there is only one tag closing.– Gabriel C.
The same mistakes keep popping up
– Gus Kiv
Yes, I know, but it’s just to improve your code. After all, it’s a comment, not an answer.
– Gabriel C.
and post the HTML part because the problem is in it.
– Guilherme Nascimento