Я создаю поля для вопроса и ответов на этот вопрос (введите ответы: радио). Я хотел бы добавить еще один вопрос для ответов с множественным выбором и текстового ответа.
Вкратце: пользователь вводит в текстовые поля вопрос и ответы. Когда генерируется появляется вопрос с ответами, например. (флажок ответов)
В базе данных есть:
table_questions
numberquestion,
questions_radio,
questions_checkbox,
questions_text.
table_answers
id,
numberquestion,
answers_radio,
answers_checkbox,
answers_text
Добавлять:
<?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'];
$table_answers[5] = $_POST['answer5'];
$table_answers[6] = $_POST['answer6'];
$table_answers[7] = $_POST['answer7'];
$query = "INSERT INTO `table_questions`
(numberquestion, questions_radio, questions_checkbox,
questions_text)
VALUES ('$numberquestion', '$radio', '$check', '$text')";
$query = "INSERT INTO `table_answers`
(numberquestion, answers_radio, answers_check,box,
answers_text)
VALUES ('$numberquestion', '$radio', '$check', '$text')";
$insert_row = $mysqli->query($query) or die($mysqli->error.__LINE__);
<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>Answer3:</label>
<input type="text" name="answer6" placeholder="Write to answer"/>
</p>
<p>
<label>Answer4:</label>
<input type="text" name="answer7" placeholder="Write to answer"/>
</p>
<p>
<label>Question with answers textfield</label>
<input type="text" name="questions_text" placeholder="Write to question"/>
</p>
Question:
<p class="question">
<?php echo $question['questions_radio']; ?>
</p><form method = "POST" action="create.php">
<ul class="table_answers">
<?php while($row = $table_answers->fetch_assoc()): ?>
<li><input name="answer" type="radio" value="<?php echo $row['id']; ?>" /><?php echo $row['answers_radio']; ?></li>
<?php endwhile; ?>
</ul>
Задача ещё не решена.
Других решений пока нет …