Coldman Posted October 11, 2007 Share Posted October 11, 2007 the code is here ession_start(); $CartID1= "1"; //$_SESSION['cartid']; $_SESSION['cartid'] = $CartID1; $_SESSION['productid'] = $_GET['var']; $_SESSION['productname'] = $_GET['var1']; $_SESSION['price'] = $_GET['var2']; $_SESSION['quantity'] = "1"; $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 ('{$_SESSION['cartid']}', '{$_SESSION['productid']}','{$_SESSION['productname']}','{$_SESSION['price']}','{$_SESSION['quantity']}','3')ON DUPLICATE KEY UPDATE Quantity=Quantity+'{$_SESSION['quantity']}', TotalPrice=Price*'{$_SESSION['quantity']}'"); if(!$query) { echo"Query Lesh"; } session_destroy(); you see the function session_destroy() i want with this session to destroy the session and in that case when i will do refresh to the site, the data will not be inserted one more time .THis code is not working please any sugestions Quote Link to comment https://forums.phpfreaks.com/topic/72757-problem-with-session-variables/ Share on other sites More sharing options...
Lukela Posted October 11, 2007 Share Posted October 11, 2007 Besides using session_destroy(); try using session_unset(); this clears all registered Data to Sessions Quote Link to comment https://forums.phpfreaks.com/topic/72757-problem-with-session-variables/#findComment-366905 Share on other sites More sharing options...
Coldman Posted October 11, 2007 Author Share Posted October 11, 2007 still not working any other sugestions Quote Link to comment https://forums.phpfreaks.com/topic/72757-problem-with-session-variables/#findComment-366906 Share on other sites More sharing options...
Lukela Posted October 11, 2007 Share Posted October 11, 2007 Why have it equal to a SESSION???? from a GET? if your just destroying it at the end? Make the $_GET's equal to a array $var['cartid']= "1"; $var['productid'] = $_GET['var']; $var['productname'] = $_GET['var1']; $var['price'] = $_GET['var2']; $var['quantity'] = "1"; than at the end put this unset($var); Got to go to sleep... if this doesnt work than sorry Quote Link to comment https://forums.phpfreaks.com/topic/72757-problem-with-session-variables/#findComment-366910 Share on other sites More sharing options...
Coldman Posted October 11, 2007 Author Share Posted October 11, 2007 and than how to insert the variable from aray to database table ?? Quote Link to comment https://forums.phpfreaks.com/topic/72757-problem-with-session-variables/#findComment-366918 Share on other sites More sharing options...
Coldman Posted October 11, 2007 Author Share Posted October 11, 2007 $CartID1= "1"; //$_SESSION['cartid']; $var['cartid']= "1"; $var['productid'] = $_GET['var']; $var['productname'] = $_GET['var1']; $var['price'] = $_GET['var2']; $var['quantity'] = "1"; 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 ('".$var['cartid']."', '".$var['productid']."', '".$var['productname']."', '".$var['price']."', '".$var['quantity']."', '".$var['price']."')ON DUPLICATE KEY UPDATE Quantity=Quantity+'".$var['quantity']."', TotalPrice=Price*Quantity"); if(!$query) { echo"Query Lesh"; } unset($var); mysql_close($con); I insert the data now but still on refresh one more insertation ?? Quote Link to comment https://forums.phpfreaks.com/topic/72757-problem-with-session-variables/#findComment-366927 Share on other sites More sharing options...
Coldman Posted October 11, 2007 Author Share Posted October 11, 2007 any idea ? Quote Link to comment https://forums.phpfreaks.com/topic/72757-problem-with-session-variables/#findComment-366928 Share on other sites More sharing options...
Coldman Posted October 11, 2007 Author Share Posted October 11, 2007 Please any help where to put this function unset($var); Quote Link to comment https://forums.phpfreaks.com/topic/72757-problem-with-session-variables/#findComment-366946 Share on other sites More sharing options...
Orio Posted October 11, 2007 Share Posted October 11, 2007 Try using in the end of your script: $_SESSION = array(); session_destroy(); Orio. Quote Link to comment https://forums.phpfreaks.com/topic/72757-problem-with-session-variables/#findComment-366953 Share on other sites More sharing options...
Coldman Posted October 11, 2007 Author Share Posted October 11, 2007 but how tu put the aray in session ? please refer to my code and write done one example if possible thanks Quote Link to comment https://forums.phpfreaks.com/topic/72757-problem-with-session-variables/#findComment-366959 Share on other sites More sharing options...
Orio Posted October 11, 2007 Share Posted October 11, 2007 I think that this way it'd work the best: <?php session_start(); if($_SESSION['ref'] == $_SERVER['PHP_SELF'].$_SERVER['QUERY_STRING']) die("<script>alert('No refreshing!');<script>Do not refresh this page!"); $CartID1= "1"; //$_SESSION['cartid']; $_SESSION['cartid'] = $CartID1; $_SESSION['productid'] = $_GET['var']; $_SESSION['productname'] = $_GET['var1']; $_SESSION['price'] = $_GET['var2']; $_SESSION['quantity'] = "1"; $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 ('{$_SESSION['cartid']}', '{$_SESSION['productid']}','{$_SESSION['productname']}','{$_SESSION['price']}','{$_SESSION['quantity']}','3')ON DUPLICATE KEY UPDATE Quantity=Quantity+'{$_SESSION['quantity']}', TotalPrice=Price*'{$_SESSION['quantity']}'"); if(!$query) { echo"Query Lesh"; } //Dont add session_destroy() $_SESSION = array(); $_SESSION['ref'] = $_SERVER['PHP_SELF'].$_SERVER['QUERY_STRING']; ?> Orio. Quote Link to comment https://forums.phpfreaks.com/topic/72757-problem-with-session-variables/#findComment-366964 Share on other sites More sharing options...
Coldman Posted October 11, 2007 Author Share Posted October 11, 2007 In this case i will not be able to use any buttons that will refer to the same page ? Quote Link to comment https://forums.phpfreaks.com/topic/72757-problem-with-session-variables/#findComment-366968 Share on other sites More sharing options...
Orio Posted October 11, 2007 Share Posted October 11, 2007 You can refer to the same page, but without the exact same GET variables in the exact same order. Orio. Quote Link to comment https://forums.phpfreaks.com/topic/72757-problem-with-session-variables/#findComment-366972 Share on other sites More sharing options...
Orio Posted October 11, 2007 Share Posted October 11, 2007 Btw, if you want this to work, you need to add in the form that is in the page that's before this one, this line (in the top for an example): $_SESSION['ref']=0; Orio. Quote Link to comment https://forums.phpfreaks.com/topic/72757-problem-with-session-variables/#findComment-366973 Share on other sites More sharing options...
Coldman Posted October 11, 2007 Author Share Posted October 11, 2007 Now its working, but there is another problem, since the code is used for shopping cart i can not put in shoping cart one product more times this means i get the error do not use refresh any time I am trying to put the same product one more time ? Quote Link to comment https://forums.phpfreaks.com/topic/72757-problem-with-session-variables/#findComment-366978 Share on other sites More sharing options...
Coldman Posted October 11, 2007 Author Share Posted October 11, 2007 is there any technique just to destroy the variables or sessions Quote Link to comment https://forums.phpfreaks.com/topic/72757-problem-with-session-variables/#findComment-366981 Share on other sites More sharing options...
Orio Posted October 11, 2007 Share Posted October 11, 2007 That's why I wrote this: Btw, if you want this to work, you need to add in the form that is in the page that's before this one, this line (in the top for an example): $_SESSION['ref']=0; Orio. Orio. Quote Link to comment https://forums.phpfreaks.com/topic/72757-problem-with-session-variables/#findComment-366988 Share on other sites More sharing options...
Coldman Posted October 11, 2007 Author Share Posted October 11, 2007 tried bout not working yet i put the code here <?php session_start(); $_SESSION['ref']=0; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>........... Damn what to do with this Quote Link to comment https://forums.phpfreaks.com/topic/72757-problem-with-session-variables/#findComment-366993 Share on other sites More sharing options...
Orio Posted October 11, 2007 Share Posted October 11, 2007 It should work now. Try again. Orio. Quote Link to comment https://forums.phpfreaks.com/topic/72757-problem-with-session-variables/#findComment-366996 Share on other sites More sharing options...
Coldman Posted October 11, 2007 Author Share Posted October 11, 2007 Nothing Quote Link to comment https://forums.phpfreaks.com/topic/72757-problem-with-session-variables/#findComment-366997 Share on other sites More sharing options...
Coldman Posted October 11, 2007 Author Share Posted October 11, 2007 what if the coming variables i put them in session and then destroy the session ? Quote Link to comment https://forums.phpfreaks.com/topic/72757-problem-with-session-variables/#findComment-367006 Share on other sites More sharing options...
Coldman Posted October 11, 2007 Author Share Posted October 11, 2007 Any idea how to avodie insertation on page refresh. Quote Link to comment https://forums.phpfreaks.com/topic/72757-problem-with-session-variables/#findComment-367070 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.