我尝试根据用户点击的当前主题(主题称为会话)从测验列表中显示测验。会话有练习,每次练习我都希望选择参加特定的课程测验(一个课程有5个练习和1个测验)。点击quiz
按钮后,我尝试使用当前$session_id
显示测验标题和作者,并将其与session_id
表格中的quiz_list
相关联在数据库中。
没有显示任何内容,我收到的错误如下:
注意:未定义的索引:第8行的C:\ xampp \ htdocs \ project \ quiz.php中的session_id
警告:mysqli_fetch_assoc()要求参数1为mysqli_result,第13行的C:\ xampp \ htdocs \ Project \ quiz.php中给出布尔值
exercise.php:
<?php
//build up array as iterate through while loop
$sessions_quiz_array = array();
$get_quiz = mysqli_query($con, "SELECT * FROM `quiz_list` WHERE `session_id` = $session_id");
//fetches result row as an associative array
while ($row_quizes = mysqli_fetch_assoc($get_quiz)) {
$sessions_quiz_array[] = $row_quizes;
}
//sessions_quiz_array is the associative array being looped
foreach ($sessions_quiz_array as $key => $value) {
$quiz_id = $value['id'];
$quiz_title = $value['quiz_title'];
$quiz_author = $value['quiz_author'];
?>
<a id='button' href="quiz.php?id=<?php echo $quiz_id; ?>"> Quiz</a>
<?php } ?>
quiz.php
<?php
session_start();
include("includes/database.php");
?>
<?php
//gets current
$session_id = $_GET['session_id'];
$get_quiz = "SELECT * FROM `quiz_list` WHERE `session_id` = $session_id";
$run_quiz = mysqli_query($con, $get_quiz);
$quiz_info = mysqli_fetch_assoc($run_quiz);
?>
<hr>
<div>
<h1><?php echo $quiz_info["id"]; ?> </h1>
<br>
<p><?php echo $quiz_info["quiz_title"]; ?></p>
<br>
<p><strong><?php echo $quiz_info["quiz_author"]; ?></strong></p>
</div>
<hr>
<a href="interactive_training.php" class="button previous">« Back to Training</a>
非常感谢任何帮助。
答案 0 :(得分:2)
在您的文件exercise.php
中,您的GET请求为ID
而session_id
附近quiz.php?id=
您需要在quiz.php
文件中进行以下更改。
从
改变$session_id = $_GET['session_id'];
要
$session_id = $_GET['id'];
Addiotionally你可以在执行整个页面之前添加检查,如
if(!isset($session_id))
{
exit('Session ID is missing');
}
答案 1 :(得分:1)
您的quiz.php变为: -
替换此
$session_id = $_GET['session_id'];
与
$session_id = $_GET['id'];