Skip to content

Instantly share code, notes, and snippets.

@JulienRAVIA
Last active August 6, 2019 20:55
Show Gist options
  • Save JulienRAVIA/0c2452d11d3db83417c00b8fe46449d7 to your computer and use it in GitHub Desktop.
Save JulienRAVIA/0c2452d11d3db83417c00b8fe46449d7 to your computer and use it in GitHub Desktop.
Formulaire
<?php
$event = $_GET['id'];
$query = $bdd->prepare('SELECT * FROM questions WHERE id_event = :event');
$query->execute(compact('event'));
$questions = $query->fetchAll();
?>
<form action="traitement.php" method="post">
<?php foreach($questions as $id => $question): ?>
<label for="question_<?= $id ?>"><?= $question ?></label>
<input type="text" name="questions[<?= $id ?>]" id="questiion_<?= $id ?>">
<?php endforeach; ?>
<button type="submit">Envoyer</button>
</form>
<?php
$reponses = $_POST['questions'];
foreach($reponses as $idQuestion => $reponse) {
$query = $bdd->prepare('INSERT INTO reponses(id_question, reponse, date) VALUES(:question, :reponse, :date)');
$query->execute([
'question' => $idQuestion,
'reponse' => $reponse,
'date' => date('Y-m-d')
]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment