zang8027 Posted February 4, 2009 Share Posted February 4, 2009 Im trying to pass array values using header("Location:www.page.com/page.php?toppings="); Then i need to grab the values on the next page. I cant figure out how to do it Here is my code on processAddOn.php <?php $product = $_GET['productID']; $toppings = $_GET['topping']; $restID = $_GET['restID']; $special= $_GET['special']; //Make a connection to the server... connect("servername","username","password") $link=mysql_connect("localhost","clikndin_tyler","$pass") or die("No server connection".mysql_error()); //connect to our database $db=mysql_select_db("clikndin_clickndine") or die("No Database Connection ".mysql_error()); //we need to connect to the database for product and retrieve the name/price $query="SELECT * FROM Menu WHERE restaurant_ID=$restID AND item_ID=$product"; $result=mysql_query($query); while($row = mysql_fetch_array($result)) { //Here is the product name + price var for use later and to add to cart $productName = $row['itemName']; $productPrice = $row['itemPrice']; } //if there are toppings being passed, do the following in {} if(isset($toppings)) { // start a for loop which does whats in curley braces {} $myArray = array(); //Create array Var // For each value being passed, do a loop, push array values for ($i=0; $i<count($toppings); $i++) { $toppingsArray = $toppings[$i]; array_push($myArray,$toppingsArray); }// close FOR loop $toppingsIds = implode(", ", $myArray); $query="SELECT * FROM requests WHERE itemID IN(" . $toppingsIds . ")"; $result=mysql_query($query); //declare an array $priceArr = array(); //While the rows are returned... while($row = mysql_fetch_array($result)) { $addonPrice = $row['itemPrice']; $itemName = $row['itemName']; //Push all returned add on prce into an array array_push($priceArr,$addonPrice); } //set a variable to the sum of prices $finalPrice = array_sum($priceArr); }else{} //set the session to whatever restaurant is selected incase the cart was cleared. unset($_SESSION['rest']); $_SESSION['rest'] = $restID; //Next, we need to redirect to the cart page with the new price and information from the item header("Location:addToCart.php?id=$product&restId=$restID&topping=SOMETHING&price=$finalPrice"); //close the connection mysql_close($link); ?> ?> Link to comment https://forums.phpfreaks.com/topic/143855-passing-array-with-header/ Share on other sites More sharing options...
gevans Posted February 5, 2009 Share Posted February 5, 2009 You'd be better off passing the array in a session. Link to comment https://forums.phpfreaks.com/topic/143855-passing-array-with-header/#findComment-754881 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.