调查。添加具有不同类型答案的字段(收音机,复选框,文本输入)

时间:2017-09-05 13:08:14

标签: php mysql survey

我创建问题的字段和问题的答案(类型答案:电台)。我想为多项选择答案和文字答案添加另一个问题。 简而言之:用户在文本字段中输入问题和答案。生成时出现问题与答案,例如(答案复选框)

在数据库中是:

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>

0 个答案:

没有答案
相关问题