Tworzę generator ankiet w PHP połączone z bazą danych. Pole dla pytania + odpowiedzi jednokrotnego wyboru (radio), pole dla pytania + odpowiedzi wielokrotnego wyboru (checkbox), pole dla pytania + odpowiedź tekstowa (input text). Działa tylko dla jednego typu (radio lub checkbox). Chciałbym żeby działało również dla odpowiedzi checkbox i text.
Proszę o pomoc i wskazówki odnośnie tego problemu.
Baza danych:
table_questions
numberquestion,
questions_radio,
questions_checkbox,
questions_text.
table_answers
id,
numberquestion,
answers_radio,
answers_checkbox,
answers_text
add.php
<?php include 'survey.php'; ?>
<?php
if(isset($_POST['submit'])){
$numberquestion = $_POST['numberquestion'];
$radio = $_POST['questions_radio'];
$check = $_POST['questions_check'];
$text = $_POST['questions_text'];
$table_answers = array();
$table_answers[1] = $_POST['answer1'];
$table_answers[2] = $_POST['answer2'];
$table_answers[3] = $_POST['answer3'];
$table_answers[4] = $_POST['answer4'];
$query = "INSERT INTO `table_questions`
(numberquestion, questions_radio, questions_checkbox,
questions_text)
VALUES ('$numberquestion', '$radio', '$check', '$text')";
<p>
<label>Question radio:</label>
<input type="text" name="questions_radio" placeholder="Write to question" />
</p>
<p>
<label>Answer 1:</label>
<input type="text" name="answer1" placeholder="Write to answer"/>
</p>
<p>
<label>Answer 2:</label>
<input type="text" name="answer2" placeholder="Write to answer"/>
</p>
<p>
<label>Answer 3:</label>
<input type="text" name="answer3" placeholder="Write to answer"/>
</p>
<p>
<label>Question checkbox</label>
<input type="questions_checkbox" name="questions_checkbox" placeholder="Write to question" />
</p>
<p>
<label>Answer1:</label>
<input type="text" name="answer4" placeholder="Write to answer"/>
</p>
<p>
<label>Answer2:</label>
<input type="text" name="answer5" placeholder="Write to answer"/>
</p>
<p>
<label>Question with answers textfield</label>
<input type="text" name="questions_text" placeholder="Write to question"/>
</p>