0
I have a form that is dynamic, the user chooses how many input will appear.
<div class="container">
<?php $g = $_GET['id']; ?>
<form method="post" action="upload.php?id=<?php echo $g ?>">
<?php $nome = $_POST['nome'];
$qtd = $_GET['qtd'];
$_SESSION['qtd'] = $qtd;
$a = 0;
while($a != $qtd){
$a++;
echo '
<div class="form-row">
<div class="form-group col-md-6">
<input type="text" class="form-control" id="input" name="pergunta[]" placeholder="Pergunta n° '.$a.'">
</div>
</div>
';}?>
</div>
<button type="submit" name="submit" class="btn btn-primary">Continuar</button>
</form>
Names are all passed in array, how can I be registering these Forms in the database? tried with the following php code and could not.
php
session_start();
require_once '../../../db/connect.php';
$id = $_get['id'];
foreach($_POST["pergunta"] as $pergunta) {
mysqli_query($conn,"INSERT INTO questao (questao,quiz_id) VALUES (".$pergunta.")") or die("Erro query.<br>Mensagem do servidor: ".mysqli_error());
}
Did you put the <form> tag and the action of it? If possible, put it.
– Angelo Soares
I put yes. Incidentally the action is going normally. But is not giving input in the database
– Tássio
put all the code of your form please
– Angelo Soares
edited the code.
– Tássio
try changing your $_POST and $_GET to $_REQUEST
– Angelo Soares
all-code?
– Tássio