如果有人能提供帮助,我在尝试让一个数组与会话一起工作时遇到了很多麻烦,如果我能让它工作,我就不会担心验证等问题,然后我可以扩展它。
HTML
<form method="post" action="array2.php">
Select amount of tickets you require.
<select name="options[]">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
Select the acomidation you require.
<select name="options2[]">
<option value="camping">Camping</option>
<option value="caravan">Caravan</option>
</select>
<input type="submit" value="Go!" />
</form>
数组2.php
<?php
session_start();
$checked = $_POST['options'];
$checked2 = $_POST['options2'];
$_SESSION['user'] = true;
$_SESSION['checked'] = $checked;
$_SESSION['checked2'] = $checked2;
header('Location: array3.php');
?>
数组3.php
<?php
session_start();
if(!isset($_SESSION['user'])){
die("To access this page, you need to <a href='register.html'>LOGIN</a>");
}
$checked = $_SESSION['checked'];
$checked2 = $_SESSION['checked2'];
?>
<?php
for($i=0; $i < count($checked && $checked2); $i++){
echo "You have selected to receive " . $checked[$i] . " tickets<br/>";
echo "And you have selected to receive " . $checked2[$i] . " for accommodation are you sure? <br/>";
}
?>
主要问题是这些值没有从array2
into传递array3
,欢迎任何帮助。
编辑 - 这工作正常,直到我尝试添加会话以使其在多个页面上工作,所以我确定这就是问题所在
EDIT2 - 感谢所有帮助我工作的人,当我拿出它时
$checked = $_POST['options'];
$checked2 = $_POST['options2'];
从数组 3 开始,它起作用了 :) 非常感谢!