php$\u GET将回显,但之后显示为空

php$\u GET将回显,但之后显示为空,php,get,Php,Get,我觉得这很直截了当。我有一张这样的照片: $cameFromCat = $_GET['cat']; echo $cameFromCat; if ($_POST['submission'] == "Continue Shopping") { Header("location: index.php?cat=" . $cameFromCat); } 这会像预期的那样读出“卡片”,所以稍后我会这样问: $cameFromCat = $_GET['cat']; echo $cameFrom

我觉得这很直截了当。我有一张这样的照片:

$cameFromCat = $_GET['cat'];
echo $cameFromCat;
if ($_POST['submission'] == "Continue Shopping") {

    Header("location: index.php?cat=" . $cameFromCat);

}
这会像预期的那样读出“卡片”,所以稍后我会这样问:

$cameFromCat = $_GET['cat'];
echo $cameFromCat;
if ($_POST['submission'] == "Continue Shopping") {

    Header("location: index.php?cat=" . $cameFromCat);

}
该链接将我发送到
index.php?cat=
。 它不会读出“卡片”。但是,如果我硬编码变量,如:

 $cameFromCat = "Cards";
该链接将我发送到index.php?cat=Cards

这真让我发疯。我做错了什么

更新:周围代码:

$cart = $_SESSION['cart'];
$cameFromCat = $_GET['cat'];
$cameFromPage = $_GET['pagenum'];
$action = $_GET['action'];
$cardqty2 = $_POST['var'];

switch ($action) {
case 'add':
    if ($cart) {
        for ($i = 1; $i <= $cardqty2; $i++) {
            $cart .= ','.$_GET['id'];
        }
    } else {
        $cart = $_GET['id'];
        for ($i = 2; $i <= $cardqty2; $i++) {
            $cart .= ','.$_GET['id'];
        }
    }
    break;
case 'delete':
    if ($cart) {
        $items = explode(',',$cart);
        $newcart = '';
        foreach ($items as $item) {
            if ($_GET['id'] != $item) {
                if ($newcart != '') {
                    $newcart .= ','.$item;
                } else {
                    $newcart = $item;
                }
            }
        }
        $cart = $newcart;
    }
    break;
case 'update':

    if ($_POST['submission'] == "Update") {

    if ($cart) {
        $newcart = '';
        foreach ($_POST as $key=>$value) {
            if (stristr($key,'qty')) {
                $id = str_replace('qty','',$key);
                $items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart);
                $newcart = '';
                foreach ($items as $item) {
                    if ($id != $item) {
                        if ($newcart != '') {
                            $newcart .= ','.$item;
                        } else {
                            $newcart = $item;
                        }
                    }
                }
                for ($i=1;$i<=$value;$i++) {
                    if ($newcart != '') {
                        $newcart .= ','.$id;
                    } else {
                        $newcart = $id;
                    }
                }
            }
        }
    }
    $cart = $newcart;
    break;

}

if ($_POST['submission'] == "Checkout") {

 Header("Location: address.php");

}

if ($_POST['submission'] == "Continue Shopping") {

 Header("location: index.php?cat=" . $cameFromCat);

}
$cart=$\u会话['cart'];
$cameFromCat=$_GET['cat'];
$cameFromPage=$_GET['pagenum'];
$action=$_GET['action'];
$cardqty2=$_POST['var'];
开关($动作){
案例“添加”:
如果($cart){

对于($i=1;$i请确保已将所有POST和GET值正确发送到脚本:

// check if GET['cat'] isset
if(!isset($_GET['cat'])) {
    die('GET.cat not set');
}

// check if POST['submissuion'] isset    
if(!isset($_POST['submission'])) {
   die('POST.submission not set');
}

$cameFromCat = $_GET['cat'];
echo $cameFromCat;

if ($_POST['submission'] == "Continue Shopping") {
    Header("location: index.php?cat=" . $cameFromCat);
}

我认为问题与开关条件有关

请看一下代码的这一部分:

case 'update':

    if ($_POST['submission'] == "Update") {

    if ($cart) {
        $newcart = '';
        foreach ($_POST as $key=>$value) {
            if (stristr($key,'qty')) {
                $id = str_replace('qty','',$key);
                $items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart);
                $newcart = '';
                foreach ($items as $item) {
                    if ($id != $item) {
                        if ($newcart != '') {
                            $newcart .= ','.$item;
                        } else {
                            $newcart = $item;
                        }
                    }
                }
                for ($i=1;$i<=$value;$i++) {
                    if ($newcart != '') {
                        $newcart .= ','.$id;
                    } else {
                        $newcart = $id;
                    }
                }
            }
        }
    }
    $cart = $newcart;
    break;

}

显示更多的代码,因为这不太容易。您必须在某个地方重置变量。echo和if语句之间发生了什么?您是否
POST
ing到一个包含
GET
变量的URL?如果您的头()呼叫是在一个函数中可能它不是来自猫?该死的狗…@Raidenace-这取决于你:-)