Jump to content

Avoid buuton back and page refresh double insertation ??


Recommended Posts

Do you have a file that is included at the top of every script you write? That is called the header file. If you don't have one, then your going to have to put this at the top of all your scripts.

i don't have header file and i putet the code in every script but still not working

 

here it the code

please see what we can do to prevent this problem

<?php

header("Cache-control: private");

session_start();

 

$CartID1= "1";

 

//if($_SESSION['isok']){

 

$_SESSION['cartid']=$CartID1;

$_SESSION['quantity']="1";

$_SESSION['productid']=$_GET['var'];

$_SESSION['productname']=$_GET['var1'];

$_SESSION['price']=$_GET['var2'];

 

 

$productid=$_SESSION['productid'];

$cartid= $_SESSION['cartid'];

$productname=$_SESSION['productname'];

$price=$_SESSION['price'];

$quantity= $_SESSION['quantity'];

 

                                   

 

 

 

 

echo $price;

$con = mysql_connect("localhost","root","");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

 

 

mysql_select_db("manvisdatabse", $con);

$query  = mysql_query("INSERT INTO cart (CartID,ProductID,ProductName,Price, Quantity, TotalPrice) VALUES ('$cartid',

'$productid', '$productname', '$price', '$quantity', '$price')ON DUPLICATE KEY UPDATE Quantity=Quantity+'$quantity', TotalPrice=Price*Quantity");

 

unset($productid);

unset($cartid);

unset($productname);

unset($price);

unset($quantity);

if(!$query)

{

echo"Query Lesh";

}

 

 

mysql_close($con);

 

 

I think the only way you can go, is to check if you have that information in the database already, and if you do, give them an error.

 

So once they add the item to the cart and press refresh, instead of adding the item again, it will give them an error saying that the item has already been added.

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.