Session destroy not working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Coldman
Forum Newbie
Posts: 15
Joined: Thu Sep 06, 2007 10:15 am

Session destroy not working

Post by Coldman »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Code: Select all

session_start();
$CartID1= "1"; 
$_SESSION['cartid']=$CartID1;
$_SESSION['quantity']="1";
$_SESSION['productid']=$_GET['var'];
$_SESSION['productname']=$_GET['var2'];
$_SESSION['price']=$_GET['var2'];


 $productid=$_SESSION['productid'];
 $cartid=$_SESSION['cartid'];
 $productname=$_SESSION['productname'];
 $price=$_SESSION['price'];
 $quantity=$_SESSION['quantity'];
                                      //$_SESSION['cartid'];


                                     //$_SESSION['cartid'];

 
 

 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");


if(!$query)
{
echo"Query Lesh";
}

session_unset();
mysql_close($con);

I use this code to avoide duble insertation but is not working please any help


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
jeffery
Forum Contributor
Posts: 105
Joined: Mon Apr 03, 2006 3:13 am
Location: Melbourne, Australia
Contact:

Post by jeffery »

You are un-setting the session but you are not checking the sessions are setting before inserting the record.

Code: Select all

if ( (isset($_SESSION['cartid'])) && (isset($_SESSION['quantity'])) && (isset($_SESSION['productid'])) && (isset($_SESSION['productname'])) && (isset($_SESSION['price'])) )
{
    // Then do the insert stuff
}
Post Reply