Jump to content

Recommended Posts

Hi,

 

this is the last page of my shopping cart where customer can write his or her details...

My problem is that after submitting the form, session doesn't remove... When i go back

to cart then i see all items in cart...

 

Two this...

 

1st- How to remove session after submitting form

2nd- How can i ask script to move to other page like (done.php) after submitting form.

 

Please show me the way :)

 

Here is the code

 

<?php
   //error_reporting(E_ERROR | E_PARSE);

   require_once('script/shoppingcart.php');
include("script/functions.php");

   if(isset($_REQUEST['command']) && $_REQUEST['command']=='update'){
    $name=$_REQUEST['name'];
    $email=$_REQUEST['email'];
    $address=$_REQUEST['address'];
    $phone=$_REQUEST['phone'];

    $result=mysql_query("insert into customers values('','$name','$email','$address','$phone')");
    $customerid=mysql_insert_id();
    $date=date('Y-m-d');
    $result=mysql_query("insert into orders values('','$date','$customerid')");
    $orderid=mysql_insert_id();

    $max=count($_SESSION['cart']);
    for($i=0;$i<$max;$i++){
	    $pid=$_SESSION['cart'][$i]['productid'];
	    $q=$_SESSION['cart'][$i]['qty'];
	    $price=get_price($pid);
	    mysql_query("insert into order_detail values ($orderid,$pid,$q,$price)");
    }
    die('Thank You! your order has been placed!');
   }
?>

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Billing Info</title>
<script language="javascript">
function validate(){
 var f=document.form1;
 if(f.name.value==''){
  alert('Your name is required');
  f.name.focus();
  return false;
 }
 f.command.value='update';
 f.submit();
}
</script>
</head>

<body>
<form name="form1" onsubmit="return validate()">
   <input type="hidden" name="command" />
<div align="center">
    <h1 align="center">Billing Info</h1>
    <table border="0" cellpadding="2px">
	 <tr><td>Order Total:</td><td><?php echo get_order_total()?></td></tr>
	    <tr><td>Your Name:</td><td><input type="text" name="name" /></td></tr>
	    <tr><td>Address:</td><td><input type="text" name="address" /></td></tr>
	    <tr><td>Email:</td><td><input type="text" name="email" /></td></tr>
	    <tr><td>Phone:</td><td><input type="text" name="phone" /></td></tr>
	    <tr><td> </td><td><input type="submit" value="Place Order" /></td></tr>
    </table>
</div>
</form>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/272731-removeing-a-session/
Share on other sites

Ok to redirect i make like this and it works

 

$url = 'done.php';

header('Location: '.$url);

 

But i can not understand unset().

 

Please help me with this by giving example

 

I believe this is what she means.

 

unset($_SESSION['name']);
header('location: done.php');
die();

Link to comment
https://forums.phpfreaks.com/topic/272731-removeing-a-session/#findComment-1403457
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.