2015-08-30 77 views
0

我試圖根據用戶點擊的當前主題(主題稱爲會話)從測驗列表中顯示測驗。會議有練習,並且我希望每次練習都能參加特定的會話測驗(一節有5個練習和1個測驗)。當單擊quiz按鈕時,我試圖使用當前的$session_id顯示測驗題目和作者,並將其與數據庫中的quiz_list表中的session_id鏈接起來。用C SESSION_ID:通過php和html顯示測驗

沒有顯示的是,我得到這樣的錯誤:

注意:未定義指數\ XAMPP \ htdocs中\上線項目\ quiz.php 8

警告:mysqli_fetch_assoc ()預計參數1被mysqli_result,在C中給出布爾:\ XAMPP \ htdocs中\上線項目\ quiz.php 13

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">&laquo; Back to Training</a> 

任何幫助將不勝感激。

+0

@FuzzyTree感謝指出了這一點!修復! – Davidaj

回答

2

在你的文件exercise.php的GET請求IDsession_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'); 
} 
+0

添加驗證並將測驗按鈕網址更改爲: Quiz它工作正常,謝謝! – Davidaj

+0

@Davidaj我很高興它適合你。在'?> && id = <?php e'附近的鏈接中有'&&'雙重符號 – Hassaan

1

你quiz.php前添加檢查變爲: -

替換此

$session_id = $_GET['session_id']; 

$session_id = $_GET['id'];