Php I';m没有从会话变量集合中获取结果值

Php I';m没有从会话变量集合中获取结果值,php,session,Php,Session,我已经创建了以下页面。 1.questions.php 2.functions.php 3.result.php 提交questions.php表单上的问题表单时,我已经在page function.php上设置了会话变量的值。functions.php代码运行时,我已经在result.php页面上回显了会话变量的值。但是我无法获取会话值结果。会话值结果为空。请任何人帮助 functions.php if(isset($_POST['question_form']))

我已经创建了以下页面。 1.questions.php 2.functions.php 3.result.php

提交questions.php表单上的问题表单时,我已经在page function.php上设置了会话变量的值。functions.php代码运行时,我已经在result.php页面上回显了会话变量的值。但是我无法获取会话值结果。会话值结果为空。请任何人帮助

       functions.php

    if(isset($_POST['question_form']))
    {
    global $conn;
    if (!isset($_SESSION['result'])) {
    $result = 0;
    $_SESSION['result'] = 0;
    }
    if (!isset($_SESSION['attempted'])) {
    $attempted = 0;
    $_SESSION['attempted'] = 0;
    }
    $resArray = array();
    $resArray['message'] = '';
    $resArray['status'] = '';
    $no = $_POST['no'];
    $postedAnswer = $_POST['answer_'.$no];
    $question_id = $_POST['question_id'];
    $subject_id = $_POST['subject_id'];

    $sql = "SELECT True_answer FROM question WHERE QuestionId = '$question_id' AND SubjectId = '$subject_id'";
    $result = mysqli_query($conn, $sql);
    $row = mysqli_fetch_assoc($result);

    $True_answer = $row['True_answer'];

    if($postedAnswer === $True_answer)
    {

        $result = $_SESSION['result'];
        $result++;
        $_SESSION['result'] = $result;
    }
        $attempted = $_SESSION['attempted'];
        $attempted++;
        $_SESSION['attempted'] = $attempted;
    $resArray['status'] = true;
    //$resArray['q_id'] = $no;
    $resArray['message'] = 'Submitted Successfully';
    echo json_encode($resArray);
    exit();
}
=======questions.php========

        <form action="includes/functions.php" id="question_form_<?php echo $j; ?>"   >
                                   <div class='container' >
                                   <div class='row'>
                                   <div class='col-lg-12'>
      <div class='thumbnail'>

    <p id="question_description">Q.<?php echo $i; ?><br><?php echo $row['QuestionDescription']; ?></p>
      <div class="questions_options">
        <label><input type="radio" id="btn_radio" name="answer_<?php echo $j; ?>" value="<?php echo $row['Option1']; ?>"><?php echo $row['Option1']; ?></input></label><br>


        <label><input type="radio" id="btn_radio" name="answer_<?php echo $j; ?>" value="<?php echo $row['Option2']; ?>"><?php echo $row['Option2']; ?></input></label><br>

        <label><input type="radio" id="btn_radio" name="answer_<?php echo $j; ?>" value="<?php echo $row['Option3']; ?>"><?php echo $row['Option3']; ?></input></label><br>

        <label><input type="radio" id="btn_radio" name="answer_<?php echo $j; ?>" value="<?php echo $row['Option4']; ?>"><?php echo $row['Option4']; ?></input></label><br><br>
              <input type="hidden" name="question_id" value="<?php echo $row['QuestionId'] ?>">
              <input type="hidden" name="subject_id" value="<?php echo $row['SubjectId'] ?>">
              <input type="hidden" name="question_form" value="question_form">
              <input type="hidden" name="no" value="<?php echo $j; ?>">
              <button class="btn btn-primary btn-sm" id="btn_submit">Submit<i class="glyphicon glyphicon-arrow-right" >

              </i></button>      
        </div>



  </div>
  </div>

  </div>

  </div>

   </form>







请使用session\u start()函数启动会话

是的,我已经在每个页面上启动了session\u start()函数,但它仍然不起作用。sujivasagamDid你得到了$result这样的结果吗?你打印并检查了吗?是的,我在result.php页面上检查了我的结果,但是当我将if-else函数放在reuslt.php中时,asnwer变为“空”。为什么要使用“==”?尝试“==”我需要匹配用户答案和数据库答案是否相同,因为我使用了这个。实际上,该===检查===之前和之后的值是否相同;在使用session变量的页面顶部添加这个。我已经在每个页面上启动了session_start()函数,但是仍然没有得到想要的结果
<table class="table table-striped table-hover" id="result_table" >

    <thead>
      <tr>
        <th style="text-align: center;">Total Questions</th>
        <th style="text-align: center;">Attempted Questions</th>
        <th style="text-align: center;">Total Marks</th>
        <th style="text-align: center;">Obtained Marks</th>
      </tr>
    </thead>
    <tbody>
    <tr>
        <td style="text-align: center;"><?php echo $number_of_questions;?></td>
        <td style="text-align: center;"><?php echo $_SESSION['attempted']; ?></td>
        <td style="text-align: center;"><?php if(!isset($_SESSION['result']))
      {
        echo "empty";
      }
      else
      {
        echo $_SESSION['result'];
      }
      ?></td>
        <td style="text-align: center;"><?php echo $marks_obtained;?></td>
    </tr>
    </tbody>
    </table>