您好我遇到了问题,我无法取消会话,任何人都可以发现错误吗?我的想法是通过这个过程直到数组4,其中一个会话已被取消,然后返回到数组3,并且在array4中删除的会话应该消失了......但它没有消失,我希望这是有道理的,谢谢所有的帮助。
HTML
<form action="array2.php" method="post">
<select name="tickets">
Select amount of tickets you require.
<option value=""></option>
<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="accom">
<option value=""></option>
<option value="camping">Camping</option>
<option value="caravan">Caravan</option>
</select>
<input name="submit" type="submit" value="submit">
</form>
数组2
<?php
session_start();
if(isset($_POST['submit'])){
if($_POST['tickets'] == "" || $_POST['accom'] == ""){
header("Location: error.html");
exit;
}else{
$tickets = $_POST['tickets'];
$accom = $_POST['accom'];
$_SESSION['tickets'] = $tickets;
$_SESSION['accom'] = $accom;
header('Location: array3.php');
}
}
&GT;
ARRAY3
<?php
session_start();
$tickets = $_SESSION['tickets'];
$accom = $_SESSION['accom'];
?>
<form method="post" action="array4.php">
<input type="submit" value="remove" />
</form>
<?php
for($i=0; $i < count($tickets); $i++){
echo "You have selected to recive " . $tickets[$i] . " tickets<br/>";
}
for($i=0; $i < count($accom); $i++){
echo "And you have selected to recive " . $accom[$i] . " for accommodation are you sure? <br/>";
}
?>
array4
<?php
session_start();
if(isset($_POST['remove'])){
unset($_SESSION['accom']);
}
$tickets = $_SESSION['tickets'];
?>
<form method="post" action="array3.php">
<input type="submit" value="go back?" />
</form>
<?php
for($i=0; $i < count($tickets); $i++){
echo "You have selected to recive " . $tickets[$i] . " tickets<br/>";
}
for($i=0; $i < count($accom); $i++){
echo "And you have selected to recive " . $accom[$i] . " for accommodation are you sure? <br/>";
}
?>
答案 0 :(得分:0)
更改此
value="remove"
in(或只是添加此内容)
name="remove"
并且不要使用for,for get a array,使用简单的foreach
foreach($tickets as $ticket){
echo "You have selected to recive $ticket tickets<br/>";
}
答案 1 :(得分:0)
而不是:
if(isset($_POST['remove'])){
unset($_SESSION['accom']);
}
你需要这个:
if(isset($_POST['submit']) && $_POST['submit'] == 'remove'){
unset($_SESSION['accom']);
}
$_POST
变量将表单变量的名称而不是值作为键。