Coldman Posted October 11, 2007 Share Posted October 11, 2007 I have a big problem with an page, every time a make refresh the data are inserting one more time the same happens with back button, does any one knows how to avoid this big problem, thanks in advance Link to comment https://forums.phpfreaks.com/topic/72792-avoid-buuton-back-and-page-refresh-double-insertation/ Share on other sites More sharing options...
pocobueno1388 Posted October 11, 2007 Share Posted October 11, 2007 In your header file, put this line of code at the top header("Cache-control: private"); Link to comment https://forums.phpfreaks.com/topic/72792-avoid-buuton-back-and-page-refresh-double-insertation/#findComment-367117 Share on other sites More sharing options...
Coldman Posted October 11, 2007 Author Share Posted October 11, 2007 where to put that header ? Link to comment https://forums.phpfreaks.com/topic/72792-avoid-buuton-back-and-page-refresh-double-insertation/#findComment-367140 Share on other sites More sharing options...
pocobueno1388 Posted October 11, 2007 Share Posted October 11, 2007 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. Link to comment https://forums.phpfreaks.com/topic/72792-avoid-buuton-back-and-page-refresh-double-insertation/#findComment-367145 Share on other sites More sharing options...
Coldman Posted October 11, 2007 Author Share Posted October 11, 2007 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); Link to comment https://forums.phpfreaks.com/topic/72792-avoid-buuton-back-and-page-refresh-double-insertation/#findComment-367154 Share on other sites More sharing options...
Coldman Posted October 11, 2007 Author Share Posted October 11, 2007 Any other idea how to avoid insertation on refresh ? Link to comment https://forums.phpfreaks.com/topic/72792-avoid-buuton-back-and-page-refresh-double-insertation/#findComment-367185 Share on other sites More sharing options...
Coldman Posted October 11, 2007 Author Share Posted October 11, 2007 header("Cache-control: private"); this works only for back button Link to comment https://forums.phpfreaks.com/topic/72792-avoid-buuton-back-and-page-refresh-double-insertation/#findComment-367191 Share on other sites More sharing options...
Coldman Posted October 11, 2007 Author Share Posted October 11, 2007 Any help here ? Link to comment https://forums.phpfreaks.com/topic/72792-avoid-buuton-back-and-page-refresh-double-insertation/#findComment-367394 Share on other sites More sharing options...
pocobueno1388 Posted October 11, 2007 Share Posted October 11, 2007 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. Link to comment https://forums.phpfreaks.com/topic/72792-avoid-buuton-back-and-page-refresh-double-insertation/#findComment-367445 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.