Jump to content

Cart? Posting? Functions?


DarkPrince2005

Recommended Posts

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
Share on other sites

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
Share on other sites

Ok, This is a pesky one isn't it.  :facewall: Maybe you need a good developer  ;D

 

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.