Register Forms array in the database

Asked

Viewed 19 times

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.

  • I put yes. Incidentally the action is going normally. But is not giving input in the database

  • put all the code of your form please

  • edited the code.

  • try changing your $_POST and $_GET to $_REQUEST

  • all-code?

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.