ceverson25 Posted December 18, 2007 Share Posted December 18, 2007 Hi, as a PHP newbie, I am trying to change an existing PHP page that is used when visitors to my site add items to thier shopping cart. Essentially , after an item is added to the cart, the user is currently being redirected back to my site HOME page. Can this be changed so the user remins on the current page ?I have found what I believe is the line of code that redirects the user (header:location="index") , can someone please help me ?, script is belowThanks"<?phpsession_start();require_once("classes/product.cls.php");require_once("classes/category.cls.php");require_once("classes/cart.cls.php");require_once("classes/dbconn.cls.php");require_once("classes/fmt.cls.php");require_once("includes/DateUtil.inc.php");$dbobj = new DBConn; // Instanciating the DBConn Class$db = $dbobj->openConn(); // Opening the database connection//$fmtobj = new FmtData; // Instanciating the FmtData Class//$proObj = new Product;$cartObj = new Cart;$prodObj=new Product;$prodID=array();$prodID=$prodObj->getRecords($db, $_REQUEST['hidden_ProdID'], $status="All");//print_r($prodID);if($_POST["chkAdd"] == "ADD" || $_REQUEST['chkAdd'] == "ADD"){ if(empty($_SESSION['cart_sess_id'])) { $_SESSION['cart_sess_id'] = md5(uniqid("1")); } if(!empty($_POST['hidden_ProdID'])){ $CartItem = $cartObj->getRecordsByProductSession($db, $_POST['hidden_ProdID'], $_SESSION['cart_sess_id']); } elseif(!empty($_REQUEST['hidden_ProdID'])){ $CartItem = $cartObj->getRecordsByProductSession($db, $_REQUEST['hidden_ProdID'], $_SESSION['cart_sess_id']); } // Check for duplicate if(count($CartItem) > 0) { //$msg = "The item has already been added to the cart."; header("location: cart.php?msg=198"); exit; } else { $cartData = array(); $CartData['cart_sess_id'] = $_SESSION['cart_sess_id']; $CartData['prod_id'] = $_REQUEST['hidden_ProdID']; $CartData['prod_price'] = $prodID[0]['prod_price']; if(empty($_REQUEST['qty'])){ // this is for index/category/subcategory pages $CartData['prod_qty'] = 1; $CartData['prod_total'] = doubleval($prodID[0]['prod_price'] * 1); } else{ $CartData['prod_qty'] = $_REQUEST['qty']; $CartData['prod_total'] = doubleval($prodID[0]['prod_price'] * $_REQUEST['qty']); } $CartData['cart_sys_date'] = date("Y-m-d H:i:s"); // print_r($CartData); $cartObj->addRecord($db, $CartData); } header("location:index.php"); exit;}?>" Link to comment Share on other sites More sharing options...
Synook Posted December 18, 2007 Share Posted December 18, 2007 Yes, just get rid of the header("location:index.php"); line down the bottom. Link to comment Share on other sites More sharing options...
ceverson25 Posted December 18, 2007 Author Share Posted December 18, 2007 Yes, just get rid of the header("location:index.php"); line down the bottom.I tried this first and the result was still the same ?.. Link to comment Share on other sites More sharing options...
ceverson25 Posted December 18, 2007 Author Share Posted December 18, 2007 Yes, just get rid of the header("location:index.php"); line down the bottom.When I do this , the user is left with a blank screen after the product has been added to thier shopping cart,... Link to comment Share on other sites More sharing options...
justsomeguy Posted December 18, 2007 Share Posted December 18, 2007 You can change it to this:header("Location: " . $_SERVER['REQUEST_URI']); Link to comment Share on other sites More sharing options...
ceverson25 Posted December 19, 2007 Author Share Posted December 19, 2007 [quote name='justsomeguy' post='92575' date='Dec 18 2007, 06:57 PM']You can change it to this:header("Location: " . $_SERVER['REQUEST_URI']);[/quote]Thanks for the suggestion , I tried this but still the same , blank screen after adding a product, with the URL showing the script http://..../addtocart.phpAnything else I can try please ?Last few lines of the script.."// print_r($CartData); $cartObj->addRecord($db, $CartData); } header("Location: " . $_SERVER['REQUEST_URI']); exit; Link to comment Share on other sites More sharing options...
justsomeguy Posted December 19, 2007 Share Posted December 19, 2007 Well going to $_SERVER['REQUEST_URI'] goes to the same page, where do you want to go? I thought you said you wanted them to stay on the same page, that's what that will do. Do you want to redirect them back to the page where they clicked on the link from? That would be $_SERVER['HTTP_REFERER']. Link to comment Share on other sites More sharing options...
ceverson25 Posted December 20, 2007 Author Share Posted December 20, 2007 Well going to $_SERVER['REQUEST_URI'] goes to the same page, where do you want to go? I thought you said you wanted them to stay on the same page, that's what that will do. Do you want to redirect them back to the page where they clicked on the link from? That would be $_SERVER['HTTP_REFERER'].Thats done it , using referer, thanks so much for your help.! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.