0

您好,我遇到了问题,我无法取消会话设置,任何人都可以发现错误吗?这个想法是通过这个过程,直到数组 4 取消设置会话,然后返回数组 3,并且在数组 4 中删除的会话应该消失了....但它没有消失,我希望这是有道理的,谢谢所有的帮助。

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');
    }
}

?>

数组3

<?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/>";
    }
?>

数组4

<?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/>";
    }
?>
4

2 回答 2

0

改变这个

value="remove"

在(或只是添加这个)

name="remove"

并且不要使用 for,对于获取数组,使用简单的 foreach

foreach($tickets as $ticket){
    echo "You have selected to recive $ticket tickets<br/>";
}
于 2013-03-03T23:36:36.120 回答
0

而不是这个:

if(isset($_POST['remove'])){
    unset($_SESSION['accom']);
}

你需要这个:

if(isset($_POST['submit']) && $_POST['submit'] == 'remove'){
    unset($_SESSION['accom']);
}

$_POSTvariables 将表单变量的名称而不是值作为键。

于 2013-03-03T23:36:42.350 回答