tags:

views:

26

answers:

1

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>";
A: 

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.

Andrew Dunn
nope, commitbuy.php is different from PHP_SELF, since php self is a different file. Named viewcart.php