未定义的单选按钮

时间:2018-08-16 14:35:24

标签: php radio-button undefined

我正在做一个简单的测验。一次显示一个问题,单选按钮上显示3个可能的答案。每个问题的答案都存储在名为SOLUTION的数据库的表中:

enter image description here

问题是,当我运行程序时,出现以下错误:Undefined variable: solution_number. 您可以帮助我在单选按钮中定义变量solution_number吗?我不确定该怎么做。

这是我的单选按钮代码:

<form action='' method='post'>
    <input type="radio" name="choice" value= "1"  /><img src="<?php echo $row["image_path_A"] ?>"/><br>
    <input type="radio" name="choice" value= "2" /><img src="<?php echo $row["image_path_B"] ?>"><br>
    <input type="radio" name="choice" value= "3" /><img src="<?php echo $row["image_path_C"] ?>"><br>



<p2>Select difficulty level:</p2>

<form action='' method='post'>
    <select name="choose" id="choose">>
    <option value="1" <?php if($row["difficulty"]=="1") { echo "selected"; } ?> >1</option>
    <option value="2" <?php if($row["difficulty"]=="2") { echo "selected"; } ?> >2</option>
    <option value="3" <?php if($row["difficulty"]=="3") { echo "selected"; } ?> >3</option>
    <option value="4" <?php if($row["difficulty"]=="4") { echo "selected"; } ?> >4</option>
    <option value="5" <?php if($row["difficulty"]=="5") { echo "selected"; } ?> >5</option>
</select>


    <input class="buttonSubmit" type="submit" name="submit" value="Submit">
    <?php
    if ($next_question_id >= 0) {
    ?>
        <a href="?id=<?php echo $next_question_id; ?>&order=<?php echo $next_question_order; ?>" class="buttonNext" >Next Question</a>
    <?php
    }
    ?>

</form>

这是PHP:错误位于“ solution_number”中。由于尚未定义。

<?php

if (isset($_POST['submit'])) {
    $user_id = $_SESSION['user_id'];
    $user_check_query = "SELECT * FROM users WHERE id='$user_id'";
    if(isset($_POST['choice'], $_POST['choose'])){
        $choice_answer=$_POST['choice'];
        $difficulty=$_POST['choose'];

        $query = "INSERT INTO answers
                         (exercise_id_fk, student_id, difficulty_change, 
                          difficulty_student, choice_answer, correct_answer)
                VALUES ('$id','$user_id', 
                        (SELECT IF(difficulty='$difficulty','NO','YES') 
                         FROM exercises 
                         WHERE exercise_id=$id), 
                        '$difficulty', '$choice_answer', 
                        (SELECT IF(solution_number='$solution_number','1','0') 
                         FROM solution WHERE exercise_id_fk=$id))";
        $sql=mysqli_query($conn,$query);

    }
}
?>

0 个答案:

没有答案