PDA

View Full Version : problem with redirecting


swissbeets
07-08-2008, 04:18 PM
i have my function of redirect_to at the end of my shopping cart but when it gets to the redirect and is supposed to take me to the next page, it says
The requested URL /website/Productsphp was not found on this server. the value should be Products.php

why would it take that out and this function has worked for me before

here is the code


Cart.php
<?php

$product_id = $_GET[id]; //the product id from the URL
$action = $_GET[action]; //the action from the URL

//if there is an product_id and that product_id doesn't exist display an error message
if($product_id && !productExists($product_id)) {
die("Error. Product Doesn't Exist");
}

switch($action) { //decide what to do

case "add":
$_SESSION['cart'][$product_id]++; //add one to the quantity of the product with id $product_id
break;

case "remove":
$_SESSION['cart'][$product_id]--; //remove one from the quantity of the product with id $product_id
if($_SESSION['cart'][$product_id] == 0) unset($_SESSION['cart'][$product_id]); //if the quantity is zero, remove it completely (using the 'unset' function) - otherwise is will show zero, then -1, -2 etc when the user keeps removing items.
break;

case "empty":
unset($_SESSION['cart']); //unset the whole cart, i.e. empty the cart.
break;

}
redirect_to(Products.php);
?>

redirect function /*i feel like this is the problem but since it worked before i dont want to change anything */

function redirect_to( $location = NULL )
{
if ($location != NULL) {
header("Location: {$location}");
exit;
}
}

davidj
07-08-2008, 04:34 PM
your header location should be...

header("Location:$location");

plus you dont need a function for this.

if you still need or want to use a function then your argument needs to be passed as a string


redirect_to('Products.php');

swissbeets
07-08-2008, 04:40 PM
thank you very much