-2
session_start();
require_once("scripts/connect_db.php");
   $arrCount = "";
         if(isset($_GET['question'])){
              $question = preg_replace('/[^0-9]/', "", $_GET['question']);
           $output = "";
          $answers1 = "";
          $answers2 = "";
          $answers3 = "";
          $answers4 = "";
            $q = "";
        $sql = mysql_query("SELECT id FROM questions");
        $numQuestions = mysql_num_rows($sql);
       if(!isset($_SESSION['answer_array']) || $_SESSION['answer_array'] < 1){
    $currQuestion = "1";
}else{
    $arrCount = count($_SESSION['answer_array']);
}
if($arrCount > $numQuestions){
    unset($_SESSION['answer_array']);
    header("location: index.php");
    exit();
}
if($arrCount >= $numQuestions){
    echo 'finished|<p>There are no more questions. Please enter your first and last name and click next</p>
            <form action="userAnswers.php" method="post">
            <input type="hidden" name="complete" value="true">
            <input type="text" name="username">
            <input type="submit" value="Finish">
            </form>';
    exit();
}
$singleSQL = "SELECT * FROM questions WHERE id='$question' LIMIT 1 ";
$result=mysql_query($singleSQL);
if($singleSQL){
    die( mysql_error());
}
    while($row = mysql_fetch_array($result)){
        $id = $row['id'];
        $thisQuestion = $row['question'];
        $type = $row['type'];
        $question_id = $row['question_id'];
        $q = '<h2>'.$thisQuestion.'</h2>';
        $sql2 = mysql_query("SELECT * FROM answers WHERE question_id='$question' ORDER BY rand()");
        while($row2 = mysql_fetch_array($sql2)){
            $answer1 = $row2['answer1'];
            $answer2 = $row2['answer2'];
            $answer3 = $row2['answer3'];
            $answer4 = $row2['answer4'];
            $correct = $row2['correct'];
            $answers1 .= '<label style="cursor:pointer;"><input type="radio" name="rads" value="'.$correct.'">'.$answer1.'</label> 
            <input type="hidden" id="qid" value="'.$id.'" name="qid"><br /><br />
            ';
            $answers2 .= '<label style="cursor:pointer;"><input type="radio" name="rads" value="'.$correct.'">'.$answer2.'</label> 
            <input type="hidden" id="qid" value="'.$id.'" name="qid"><br /><br />
            ';
            $answers3 .= '<label style="cursor:pointer;"><input type="radio" name="rads" value="'.$correct.'">'.$answer3.'</label> 
            <input type="hidden" id="qid" value="'.$id.'" name="qid"><br /><br />
            ';
            $answers4 .= '<label style="cursor:pointer;"><input type="radio" name="rads" value="'.$correct.'">'.$answer4.'</label> 
            <input type="hidden" id="qid" value="'.$id.'" name="qid"><br /><br />
            ';
        }
        $output = ''.$q.','.$answers1.','.$answers2.','.$answers3.','.$answers4.',<span id="btnSpan"><button onclick="post_answer()">Submit</button></span>';
        echo $output;
       }
    }

它是在线考试系统上的一个项目,我能够插入数据,但在获取数据时无法显示它只是给出一个错误未定义请帮助我,我应该显示问题和四个选项并检查答案并给我分数,我的 html 去像这样

<body>
            <p id="question"></p>
                      <table>
                                   <tr>
                           <td id="answer1"><td>
                                   </tr>
                                  <tr>
                          <td id="answer2"></td>
                               </tr>
                                  <tr>
                        <td id="answer3"></td>
                               </tr>
                                    <tr>
                          <td id="answer4"></td>
                                     <tr>
                                                   </table>
4

1 回答 1

2

你的脚本总是被 die() 停止:

if($singleSQL){
    die( mysql_error());
}
于 2013-07-18T20:37:28.227 回答