A user runs the following page...it is run from custom_quote.php?id=1 (you'll get what I'm talking about down the page)
<?php
if(isset($_POST['Submit']))
{
$pages = $_POST['pages'];
$details = $_POST['details'];
if(empty($pages)) { $error = "<li>The page field was left blank.</li>"; }
if(empty($details)) { $error .= "<li>The details field was left blank.</li>"; }
if(isset($error))
{
?><ul><?php echo $error; ?></ul><?php
}else{
$sql = "INSERT INTO `tbl_web_design` (`id`, `pages`, `details`) VALUES(DEFAULT, '$pages', '$details');";
mysql_query($sql) or die("ERROR: ".$sql."<br>".mysql_error());
$_SESSION['web_design'][] = mysql_insert_id();
?><p align="center">The <a href="quote.php?id=<?php echo mysql_insert_id(); ?>&order=<?php echo $id; ?>">web design project</a> has been added to your <a href="<?php echo $PHP_SELF; ?>">shopping cart</a>.<br>
<a href="<?php echo $PHP_SELF; ?>">View Shopping Cart</a><br>
<a href="<?php echo $_POST['previous']; ?>">Go back to previous page</a><br>
<a href="<?php echo $_SERVER['REQUEST_URI']; ?>">Add another web design project</a></p>
<?php
}
}else{ ?>
<h3>Web Design</h3>
<form method="post" action="<?php echo $PHP_SELF; ?>?id=<?php echo $id; ?>">
<table width="670" border="0">
<tr>
<td width="111"><strong>Number of Pages</strong>s</td>
<td width="549"><input type="text" name="pages">
<input name="previous" type="hidden" value="<?php echo $_SERVER['HTTP_REFERER']; ?>"></td>
</tr>
<tr>
<td valign="top"><strong>Details</strong></td>
<td><textarea name="details" cols="50" rows="5"></textarea></td>
</tr>
<tr>
<td> </td>
<td><strong>Bold indicated required</strong></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="Add to Cart">
<input type="reset" name="Reset" value="Reset"></td>
</tr>
</table>
</form>
<?php
}
?>
Everything works out fine...the user fills out the form and the php server processes it by inserting it into the database and creating a session based on the id generated from the database.
Now the user goes to $PHP_SELF (let's call it custom_quote.php):
<?php include "includes/top.php"; ?>
<div id="content">
<h2 id="pageName">Custom Quote</h2>
<div class="story">
<?php
if(isset($_GET['id']))
{
include "custom_quote/".$_GET['id'].".php";
}else{
switch($_GET['act'])
{
case "clear" :
session_unregister($_SESSION) or die("Cannot clear cart. Please contact technical support.");
?><p align="center">Your <a href="<?php echo $PHP_SELF; ?>">cart</a> has been cleared successfully.<br>
<a href="javascript:history.back(1)">Go back</a></p><?php
break;
case "remove" :
foreach($product[$_GET['order']] as $name=>$table)
{
$sql = "DELETE FROM tbl_".$table." WHERE `id` = '".$_GET['oid']."' LIMIT 1";
mysql_query($sql) or die(mysql_error());
foreach($_SESSION[$table] as $index=>$val)
{
if($_GET['oid'] == $val)
{
session_unset($_SESSION[$table][$index]) or die("Error");
}
}
if(!$unset)
{
?><p>The <?php echo $name; ?> quote in your cart could not be removed. Please contact technical support.</p><?php
}else{
?><p>The <?php echo $name; ?> quote in your cart has been successfully removed.</p><?php
}
}
break;
case "modify" :
include "custom_quote/modify.php";
break;
case "checkout" :
include "custom_quote/checkout.php";
break;
default :
include "custom_quote/default.php";
break;
}
}
?>
</div>
</div>
<?php include "includes/left.php"; ?>
<?php include "includes/bottom.php"; ?>
For some reason, when the user runs custom_quote.php?act=clear - the $_SESSION variable is not cleared. Also, when the user runs custom_quote.php?act=remove&order=1&oid=5 (OID is hypothetical...it is based on the database), the session that corresponds to the OID should be cleared, but is not cleared.
WHat is going wrong?
Thanks for your help in advance.