communion Posted February 27, 2008 Share Posted February 27, 2008 Hey all, I've got a reservation form that I need to pass variables to a checkout page using $_SESSION, after the form data has been sent to sendmail.php via POST. Here's the way the form is structured, hopefully someone can help me figure out what I'm doing wrong. Reservation form PHP, name vars = html field form names: <?php session_start(); $_SESSION['name'] = 'Name'; $_SESSION['email'] = 'Email'; $_SESSION['address'] = 'Address'; $_SESSION['contactphone'] = 'ContactPhone'; $_SESSION['alternatephone'] = 'AlternatePhone'; $_SESSION['fax'] = 'Fax'; $_SESSION['eventdate'] = 'EventDate'; $_SESSION['pickuptime'] = 'PickupTime'; $_SESSION['morning_night'] = 'AmOrPm'; $_SESSION['pickupname'] = 'PickupName'; $_SESSION['pickupphone'] = 'PickupPhone'; $_SESSION['numberinparty'] = 'NumberinParty'; $_SESSION['mypreferredtransportationis'] = 'MyPreferedTransportationIs'; $_SESSION['pickupaddress'] = 'PickupAddress'; $_SESSION['pickupcity'] = 'PickupCity'; $_SESSION['pickupstate'] = 'PickupState'; $_SESSION['pickupzipcode'] = 'PickupZipCode'; $_SESSION['airportpickup'] = 'AirportPickup'; $_SESSION['destinationcity'] = 'DestinationCity'; $_SESSION['hourlyrate'] = 'HourlyRate'; $_SESSION['totalhours'] = 'TotalHours'; $_SESSION['totalcharge'] = 'TotalCharge'; $_SESSION['thirtypercentdeposit'] = 'ThirtyPercentDeposit'; $_SESSION['balancedue'] = 'BalanceDueOnPickup'; $_SESSION['totalamountduenow'] = 'amount'; $HTTP_SESSION_VARS ["Name"] = $name; // Set name = form variable $HTTP_SESSION_VARS ["Email"] = $email; $HTTP_SESSION_VARS ["Address"] = $address; $HTTP_SESSION_VARS ["ContactPhone"] = $contactphone; $HTTP_SESSION_VARS ["AlternatePhone"] = $alternatephone; $HTTP_SESSION_VARS ["Fax"] = $fax; $HTTP_SESSION_VARS ["EventDate"] = $eventdate; $HTTP_SESSION_VARS ["PickupTime"] = $pickuptime; $HTTP_SESSION_VARS ["AmOrPm"] = $morning_night; $HTTP_SESSION_VARS ["PickupName"] = $pickupname; $HTTP_SESSION_VARS ["PickupPhone"] = $pickupphone; $HTTP_SESSION_VARS ["NumberinParty"] = $numberinparty; $HTTP_SESSION_VARS ["MyPreferedTransportationIs"] = $mypreferredtransportationis; $HTTP_SESSION_VARS ["PickupAddress"] = $pickupaddress; $HTTP_SESSION_VARS ["PickupCity"] = $pickupcity; $HTTP_SESSION_VARS ["PickupState"] =$pickupstate; $HTTP_SESSION_VARS ["PickupZipCode"] = $pickupzipcode; $HTTP_SESSION_VARS ["AirportPickup"] = $airportpickup; $HTTP_SESSION_VARS ["DestinationCity"] = $destinationcity; $HTTP_SESSION_VARS ["HourlyRate"] = $hourlyrate; $HTTP_SESSION_VARS ["TotalHours"] = $totalhours; $HTTP_SESSION_VARS ["TotalCharge"] = $totalcharge; $HTTP_SESSION_VARS ["ThirtyPercentDeposit"] = $thirtypercentdeposit; $HTTP_SESSION_VARS ["BalanceDueOnPickup"] = $balancedue; $HTTP_SESSION_VARS ["amount"] = $totalamountduenow; ?> So these form vars are then sent to sendmail.php via POST: <?php session_start(); $name = $_POST['Name'] ; $email = $_POST['Email'] ; $address = $_POST['Address'] ; $contactphone = $_POST['ContactPhone'] ; $alternatephone = $_POST['AlternatePhone'] ; $fax = $_POST['Fax'] ; $eventdate = $_POST['EventDate'] ; $pickuptime = $_POST['PickupTime'] ; $morning_night = $_POST['AmOrPm'] ; $pickupname = $_POST['PickupName'] ; $pickupphone = $_POST['PickupPhone'] ; $numberinparty = $_POST['NumberinParty'] ; $mypreferredtransportationis = $_POST['MyPreferedTransportationIs'] ; $pickupaddress = $_POST['PickupAddress'] ; $pickupcity = $_POST['PickupCity'] ; $pickupstate = $_POST['PickupState'] ; $pickupzipcode = $_POST['PickupZipCode'] ; $airportpickup = $_POST['AirportPickup'] ; $destinationcity = $_POST['DestinationCity'] ; $hourlyrate = $_POST['HourlyRate'] ; $totalhours = $_POST['TotalHours'] ; $totalcharge = $_POST['TotalCharge'] ; $thirtypercentdeposit = $_POST['ThirtyPercentDeposit'] ; $balancedue = $_POST['BalanceDueOnPickup'] ; $totalamountduenow = $_POST['amount'] ; $message = " Name: $name \n Email: $email \n Address: $address \n Contact Phone: $contactphone \n Alternate Phone: $alternatephone \n Fax: $fax \n Event Date: $eventdate \n Pickup Time: $pickuptime \n Am or Pm: $morning_night \n Pickup Name: $pickupname \n Pickup Phone: $pickupphone \n Number In Party: $numberinparty \n My Preferred Transportation is: $mypreferredtransportationis \n Pickup Address: $pickupaddress \n Pickup City: $pickupcity \n Pickup State: $pickupstate \n Pickup Zip Code: $pickupzipcode \n Airport Pickup: $airportpickup \n Flat Rate: $destinationcity \n Hourly Rate: $hourlyrate \n Total Hours: $totalhours \n Total Charge: $totalcharge \n Thirty Percent Deposit: $thirtypercentdeposit \n Balance Due On Pickup: $balancedue \n Total Due Now: $totalamountduenow \n "; mail( "[email protected]", "Reservation Confirmation", $message, "From: $email" ); header( "Location: http://www.me.com/checkout.php" ); session_write_close(); ?> So the sendmail works fine, but now I need to have these same variables passed to the checkout.php in the header location, here's my checkout.php: <?php session_start(); $email = $_SESSION['Email'] ; $address = $_SESSION['Address'] ; $contactphone = $_SESSION['ContactPhone'] ; $alternatephone = $_SESSION['AlternatePhone'] ; $fax = $_SESSION['Fax'] ; $eventdate = $_SESSION['EventDate'] ; $pickuptime = $_SESSION['PickupTime'] ; $morning_night = $_SESSION['AmOrPm'] ; $pickupname = $_SESSION['PickupName'] ; $pickupphone = $_SESSION['PickupPhone'] ; $numberinparty = $_SESSION['NumberinParty'] ; $mypreferredtransportationis = $_SESSION['MyPreferedTransportationIs'] ; $pickupaddress = $_SESSION['PickupAddress'] ; $pickupcity = $_SESSION['PickupCity'] ; $pickupstate = $_SESSION['PickupState'] ; $pickupzipcode = $_SESSION['PickupZipCode'] ; $airportpickup = $_SESSION['AirportPickup'] ; $destinationcity = $_SESSION['DestinationCity'] ; $hourlyrate = $_SESSION['HourlyRate'] ; $totalhours = $_SESSION['TotalHours'] ; $totalcharge = $_SESSION['TotalCharge'] ; $thirtypercentdeposit = $_SESSION['ThirtyPercentDeposit'] ; $balancedue = $_SESSION['BalanceDueOnPickup'] ; $totalamountduenow = $_SESSION['amount'] ; ?> So I'd like to populate text from the variables like a confirmation and have it displayed on the page using ECHO like this: Your name is: <?php echo $_SESSION['name'];?> What is happening is that the sendmail works, I get the results of the form data, then the redirect to checkout.php, but the session variable is not coming through from the first form. What I get is: Your name is: Name What I'd like to do also is bring in vars like "amount" as well to pass to Paypal. Can someone shed some light on this? Where I might be heading in the wrong direction? I was under the impression that session variables declared on the first page would be accessible after the redirect happens. Any help would be most appreciated. This is my first attempt in using PHP Sessions to populate text in this way. Cheers, Communion Link to comment https://forums.phpfreaks.com/topic/93402-_session-and-html-form-variables-reservation-form/ Share on other sites More sharing options...
poirot Posted February 27, 2008 Share Posted February 27, 2008 Try to add this into each page: echo '<pre>'; print_r($_SESSION); echo '</pre>'; To check if the session is being passed correctly. Link to comment https://forums.phpfreaks.com/topic/93402-_session-and-html-form-variables-reservation-form/#findComment-478531 Share on other sites More sharing options...
redarrow Posted February 27, 2008 Share Posted February 27, 2008 wrong sesion died becouse you went from the current script with your full url....... header( "Location: http://www.me.com/checkout.php" ); corrected going to a server internal script with sessions working.... header( "Location: http://checkout.php" ); Link to comment https://forums.phpfreaks.com/topic/93402-_session-and-html-form-variables-reservation-form/#findComment-478618 Share on other sites More sharing options...
communion Posted February 28, 2008 Author Share Posted February 28, 2008 wrong sesion died becouse you went from the current script with your full url....... header( "Location: http://www.me.com/checkout.php" ); corrected going to a server internal script with sessions working.... header( "Location: http://checkout.php" ); Ok, so I changed the location to checkout.php and it is passing the array now, but not the html form vars that were filled out on the form. So, Your name: <?php echo $_SESSION['name'];?> Still = Name, instead of form var... So i added: <?php echo '<pre>'; print_r($_SESSION); echo '</pre> Which spits out the array: Array ( [name] => Name => Email [address] => Address [contactphone] => ContactPhone [alternatephone] => AlternatePhone [fax] => Fax [eventdate] => EventDate [pickuptime] => PickupTime [morning_night] => AmOrPm [pickupname] => PickupName [pickupphone] => PickupPhone [numberinparty] => NumberinParty [mypreferredtransportationis] => MyPreferedTransportationIs [pickupaddress] => PickupAddress [pickupcity] => PickupCity [pickupstate] => PickupState [pickupzipcode] => PickupZipCode [airportpickup] => AirportPickup [destinationcity] => DestinationCity [hourlyrate] => HourlyRate [totalhours] => TotalHours [totalcharge] => TotalCharge [thirtypercentdeposit] => ThirtyPercentDeposit [balancedue] => BalanceDueOnPickup [totalamountduenow] => amount [Name] => => [Address] => [ContactPhone] => [AlternatePhone] => [Fax] => [EventDate] => [PickupTime] => [AmOrPm] => [PickupName] => [PickupPhone] => [NumberinParty] => [MyPreferedTransportationIs] => [PickupAddress] => [PickupCity] => [PickupState] => [PickupZipCode] => [AirportPickup] => [DestinationCity] => [HourlyRate] => [TotalHours] => [TotalCharge] => [ThirtyPercentDeposit] => [balanceDueOnPickup] => [amount] => ) Link to comment https://forums.phpfreaks.com/topic/93402-_session-and-html-form-variables-reservation-form/#findComment-478948 Share on other sites More sharing options...
communion Posted February 28, 2008 Author Share Posted February 28, 2008 bump Link to comment https://forums.phpfreaks.com/topic/93402-_session-and-html-form-variables-reservation-form/#findComment-479280 Share on other sites More sharing options...
communion Posted February 28, 2008 Author Share Posted February 28, 2008 bump Link to comment https://forums.phpfreaks.com/topic/93402-_session-and-html-form-variables-reservation-form/#findComment-479437 Share on other sites More sharing options...
communion Posted February 28, 2008 Author Share Posted February 28, 2008 Thanks for all your help on this, I was able to resolve this issue, Problem was: session_write_close(); was set after header Also I found it much easier to use: $_SESSION = $_POST; rather than declare each session variable individually. Cheers, Communion Link to comment https://forums.phpfreaks.com/topic/93402-_session-and-html-form-variables-reservation-form/#findComment-479584 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.