Jump to content

Trying desperately to pass a product id to shopping cart page


deansaddigh

Recommended Posts

<button type="submit" class="submit" name="submit">Add to cart</button>

Use that instead of the button you have, and on cart.php Use something like this..

 

if(isset($_POST['submit'])){
$id = $_POST['productid'];
echo $id;
}

 

You need to do further tests.

Hi and thanks for all your help.

 

I have now passed my product id to my cart page and performed sql  to display the details of that product.

 

Heres the code

 

<?php 

		/*Get the product id from previos page*/
		$productid = $_GET['productid'];



		/*get the product details based on id*/
		$query = "select ProductID, ProductName, ProductPrice
		FROM product 
		WHERE ProductID = ".$productid;		
		$result = mysql_query($query, $conn)
		  or die ("Unable to perform query");
		  
		while($row= mysql_fetch_array($result))
		{
            	
            	echo $row["ProductName"];
            	echo $row["ProductPrice"];
		}

		//* Save details to the session*//



	?>

 

What i now want to do is save the product details to a session.

How do i do the next step of saving every product id thats past to this page to the session variable and not overwrite it, so then when i get to the payment section i can pass the total over to paypal?

 

 

Well,

$_SESSION['session-name'] = $id;

That would set a session, although if you're wanting to set a session for each ID without overwriting. Then try something similar to;

$_SESSION["$id"] = $id;

For product id 1, the session name will be $_SESSION["1"] which will hold the value 1.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.