Jump to content

problem with session variables


Coldman

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

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.