我觉得这很简单。我有一个$ _GET这样的:
$cameFromCat = $_GET['cat'];
echo $cameFromCat;
这会读出“牌”不如预期,所以后来我问它:
if ($_POST['submission'] == "Continue Shopping") {
Header("location: index.php?cat=" . $cameFromCat);
}
链接发送我index.php?cat=
。 它不会读出'卡片'。但是,如果我硬编码的变种,如:
$cameFromCat = "Cards";
的链接发给我的index.php猫=卡
它严重快把我逼疯了?我究竟做错了什么?
UPDATE:周围代码:
$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);
}
}
显示更多的代码,因为这是没有太大的去。您必须在某处重置变量。 – 2013-04-24 21:39:35
你的回声和你的if语句之间发生了什么? – Dan 2013-04-24 21:40:23
你是否在POST过程中包含GET变量的URL? – showdev 2013-04-24 21:41:37