目标:我想传递一个数组,其中包含从一个页面到另一个页面的值。
问题:说到第二页,我试图print_r数组,它没有任何值。它在第二页上给了我这个php通知:
注意:未定义的索引:第17行的Questionnaire_Category_2.php中的答案
这是我在第一页的代码段 Questionnaire_Category_1.php
if(isset($_POST['Choice'])){ //When the user submits the answer
$Answer[] = $_POST['Choice']; //All answers from the form will be placed in the array
session_start();
$_SESSION['answers'] = $Answer; //All values of the array will be assigned to the session variable 'answers'
header("Location: Questionnaire_Category_2.php");
}
这是第二页的代码段 Questionnaire_Category_2.php
$ANSWER[] = $_SESSION['answers']; //Get all the values from the session and store it in array and also this is the Line 17 that causes a notice message
echo "<pre>"; print_r($ANSWER); echo "</pre>";
问题:
答案 0 :(得分:0)
在会话
中添加和获取值之前执行run
session_start()
和
session_start();
$_SESSION['answers'] = $ANSWER;