我无法在以下php代码中设置单选按钮“名称”的范围

时间:2019-02-18 16:41:29

标签: php html forms while-loop

我想将单选按钮的值输入数据库表...请建议我进行任何代码修改:

<?php

$query = mysqli_query($conn,"SELECT * FROM Course_Exit_Survey_Question");

         $array = array();   
         $answer = array();
         echo "<form method='post'>";
         echo "<table border='1'>";
         echo "<tr><th>Question</th></tr>";
         $i=0;
         while ($row = $query->fetch_assoc()) {
               $array[] = $row;
               $var = "{$row['Question']}";
               echo "<tr>";
               echo "<td>";
               echo "<tr><td>$var</td></tr>";
               echo " <td><label>
               <input type='radio' value='1' name='q[<?php echo $i; ?>]'>Poor
               <input type='radio' value='2' name='q[<?php echo $i; ?>]'>Ok
               <input type='radio' value='3' name='q[<?php echo $i; ?>]'>Good
               <input type='radio' value='4' name='q[<?php echo $i; ?>]'>Medium
               <input type='radio' value='5' name='q[<?php echo $i; ?>]'>Excellent
               </label></div></td>";
               $i++;
                          }
         echo "</table>";
if (isset($_POST['submit'])){
   echo "string";
      $q1 = $_POST['q[<?php echo $i; ?>]'];
     $sql= mysqli_query($conn,"INSERT INTO Question_Answer (answer) VALUES ('$q1')") or die("MySQL Error : ".mysqli_error($conn));
      if($sql){
          echo "Data Saved";
       }else{
          echo "Data not saved";
       }
  }

此表单向用户提出问题,该问题具有使用单选按钮提供的五个选项。当用户为所有问题选择五分之一的选项并单击提交时,应将所有单选按钮值插入数据库。

0 个答案:

没有答案