DarkPrince2005 Posted August 12, 2009 Share Posted August 12, 2009 Hi all... Here is my problem: I want to be able to click on a link in the one page and have it post to itself and then call a function from an external file.it seems to do it's job, but as soon as i refresh it adds again.... how can i solve this? <?php include "functions.php"; connect(); session_start(); $user= session_id(); if ((isset($_GET['product1'])) && $_GET['product1'] != ""){ add_to_cart(); } ?><html><head></head><body><div id="product-frame"> <a name="p1"></a><form method="post" action="index.php" name="product1"> <div id="product-img"><img src="images/tcb_ladies_clear_boxes.png" height="100"/><br><a href="#1" onclick="product1();"><h6>Click here to enlarge..</h6></a></div> <div id="product-header"><h1>Ladies' clear shoe boxes</h1></div> <div id="product-info"><h2>Sort out the chaos in your cupboards with these sturdy stackable clear boxes. A convenient way to access your shoes with no fuss.</h2></div> <div id="product-description"><h3>Dimension 29.5 x 18 x 9.5cm Holds up to size 8</h3></div> <div id="price_buy"><span class="price">R190 per pack of 5 <br /></span><div class="buy"/><input type="hidden" name="product1" value="1"><a href="javascript:document.product1.submit()">Buy now!..</a></div> </form> </div> Function.php function add_to_cart(){ $sess=session_id(); $prod= $_POST['product1']; $a=run_query("insert into cart values('','$prod','1','$sess',now())"); return $a['product_id']; break; } Link to comment https://forums.phpfreaks.com/topic/169910-cart-posting-functions/ Share on other sites More sharing options...
Lyleyboy Posted August 12, 2009 Share Posted August 12, 2009 You could just unset the variables at the end of the function. unset($product1); Link to comment https://forums.phpfreaks.com/topic/169910-cart-posting-functions/#findComment-896350 Share on other sites More sharing options...
DarkPrince2005 Posted August 12, 2009 Author Share Posted August 12, 2009 unfortunately that also isn't working Link to comment https://forums.phpfreaks.com/topic/169910-cart-posting-functions/#findComment-896356 Share on other sites More sharing options...
Lyleyboy Posted August 12, 2009 Share Posted August 12, 2009 What about a nasty way to do it by setting a session variable to hold the product1 variable. Then if the session is set don't run the script again. If it's not set go for your life. Make sense? Im not a good php developer so I have to fudge things into working sometimes. Link to comment https://forums.phpfreaks.com/topic/169910-cart-posting-functions/#findComment-896364 Share on other sites More sharing options...
DarkPrince2005 Posted August 12, 2009 Author Share Posted August 12, 2009 That unfortunately also doesn't work Link to comment https://forums.phpfreaks.com/topic/169910-cart-posting-functions/#findComment-896501 Share on other sites More sharing options...
Lyleyboy Posted August 12, 2009 Share Posted August 12, 2009 Ok, This is a pesky one isn't it. Maybe you need a good developer Ok, how about using variables rather than get variables as you can then definatley reset them to mean nothing, something like $prod1 = $_Get['product1']; Don't use an isset use > "" so if ($prod1 > "" && $prod1 <> "xxx"){ Rather than if ((isset($_GET['product1'])) && $_GET['product1'] != ""){ and at the end of the script reset the $prod1 to xxx so that it will fail the if statement. Link to comment https://forums.phpfreaks.com/topic/169910-cart-posting-functions/#findComment-896557 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.