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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.