Jump to content

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/72757-problem-with-session-variables/
Share on other sites

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 :P

 

$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 ??

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.

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

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.