Jump to content

Avoid buuton back and page refresh double insertation ??


Coldman

Recommended Posts

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.

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.