deansaddigh Posted January 3, 2010 Share Posted January 3, 2010 As above really i want to pass the product id to the shopping cart page i have this is this correct echo "<a href=cart.php? '.$productid.'>Add to cart</a>" Link to comment https://forums.phpfreaks.com/topic/187036-trying-desperately-to-pass-a-product-id-to-shopping-cart-page/ Share on other sites More sharing options...
Irresistable Posted January 3, 2010 Share Posted January 3, 2010 <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. Link to comment https://forums.phpfreaks.com/topic/187036-trying-desperately-to-pass-a-product-id-to-shopping-cart-page/#findComment-987712 Share on other sites More sharing options...
deansaddigh Posted January 3, 2010 Author Share Posted January 3, 2010 Sorry i modified my post, is this correct now? Link to comment https://forums.phpfreaks.com/topic/187036-trying-desperately-to-pass-a-product-id-to-shopping-cart-page/#findComment-987714 Share on other sites More sharing options...
RussellReal Posted January 3, 2010 Share Posted January 3, 2010 echo "<a href='cart.php?productid={$productid}'>Add to cart</a>"; Link to comment https://forums.phpfreaks.com/topic/187036-trying-desperately-to-pass-a-product-id-to-shopping-cart-page/#findComment-987717 Share on other sites More sharing options...
deansaddigh Posted January 3, 2010 Author Share Posted January 3, 2010 Thanks guys i got it working with this code echo "<a href=cart.php? '.$productid'>Add to cart</a>"; Link to comment https://forums.phpfreaks.com/topic/187036-trying-desperately-to-pass-a-product-id-to-shopping-cart-page/#findComment-987721 Share on other sites More sharing options...
deansaddigh Posted January 3, 2010 Author Share Posted January 3, 2010 How would i now retrieve my id, i have this code but obviously its wrong <?php $productid = mysql_real_escape_string($_POST["productid"]); echo $_POST['productid']; ?> Link to comment https://forums.phpfreaks.com/topic/187036-trying-desperately-to-pass-a-product-id-to-shopping-cart-page/#findComment-987724 Share on other sites More sharing options...
Irresistable Posted January 3, 2010 Share Posted January 3, 2010 Why have you defined $productid and not use it? What are you aiming to do exactly. That should echo and ID. What do you want to do with the ID? Link to comment https://forums.phpfreaks.com/topic/187036-trying-desperately-to-pass-a-product-id-to-shopping-cart-page/#findComment-987735 Share on other sites More sharing options...
deansaddigh Posted January 3, 2010 Author Share Posted January 3, 2010 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? Link to comment https://forums.phpfreaks.com/topic/187036-trying-desperately-to-pass-a-product-id-to-shopping-cart-page/#findComment-987746 Share on other sites More sharing options...
Irresistable Posted January 3, 2010 Share Posted January 3, 2010 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. Link to comment https://forums.phpfreaks.com/topic/187036-trying-desperately-to-pass-a-product-id-to-shopping-cart-page/#findComment-987752 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.