doumanshan6314 2010-09-21 03:32
浏览 21
已采纳

如何使用php self并将信息传递给其他页面

I'm doing a little project that acts like a cart. When I click this link:

echo "<td><a href=\"$_SERVER[PHP_SELF]?action=zero&commitbuy.php?ids=$id&qoh=$qtyhand&qtb=$quantity\">ok</a></td>";

I want the program to perform the action zero, which will delete the product from the cart table,when I click the ok link:

<?php

    $product_id = $_GET['id'];   
    $action     = $_GET['action']; 


    if($product_id && !productExists($product_id)) {
        die("Error. Product Doesn't Exist");
    }

    switch($action) {   

        case "add":
            $_SESSION['cart'][$product_id]++; 
        break;

        case "remove":
            $_SESSION['cart'][$product_id]--; 
            if($_SESSION['cart'][$product_id] == 0) unset($_SESSION['cart'][$product_id]); 
        break;

        case "zero":
            $_SESSION['cart'][$product_id]==0;

        break;

        case "empty":
            unset($_SESSION['cart']); 
        break;

    }
?>

Then also, commitbuy.php would update the quantity of that certain product. What can you suggest that I would do with this. It doesn't seem to work. When I add this code:

$_SERVER[PHP_SELF]?action=zero

to this one:

 echo "<td><a href=\"commitbuy.php?ids=$id&qoh=$qtyhand&qtb=$quantity\">ok</a></td>";
  • 写回答

1条回答 默认 最新

  • doq1969 2010-09-21 03:46
    关注

    You are getting the error because on some (but not all) servers, PHP_SELF is already a defined constant, so $_SERVER[PHP_SELF] is the same as calling $_SERVER['/path/commitbuy.php'] To fix it use $_SERVER['PHP_SELF'] instead.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应