skot Posted July 21, 2009 Share Posted July 21, 2009 Hi All, I'm trying to use a multi-page form to collect form entered data and email this to myself. I have tried multiple methods of doing this and using sessions seems to be the answer. The issue is that no variables are actually passed over, thus not a lot is emailed. URL: http://www.centurysoftware.co.uk/demonstrations.html I am using cs_bookdemo.php to collect name, numbers and addresses. This form posts to cs_bookdemo2.php, which contains the following code:- <?php session_start(); $_SESSION['name']=!empty($_POST['name'])? htmlspecialchars($_POST['name']) : null; $_SESSION['company']=!empty($_POST['company'])? htmlspecialchars($_POST['company']) : null; $_SESSION['sector']=!empty($_POST['sector'])? htmlspecialchars($_POST['sector']) : null; $_SESSION['tel']=!empty($_POST['tel'])? htmlspecialchars($_POST['tel']) : null; $_SESSION['mob']=!empty($_POST['mob'])? htmlspecialchars($_POST['mob']) : null; $_SESSION['emai']=!empty($_POST['email'])? htmlspecialchars($_POST['email']) : null; $_SESSION['a1']=!empty($_POST['a1'])? htmlspecialchars($_POST['a1']) : null; $_SESSION['a2']=!empty($_POST['a2'])? htmlspecialchars($_POST['a2']) : null; $_SESSION['a3']=!empty($_POST['a3'])? htmlspecialchars($_POST['a3']) : null; $_SESSION['a4']=!empty($_POST['a4'])? htmlspecialchars($_POST['a4']) : null; $_SESSION['a5']=!empty($_POST['a5'])? htmlspecialchars($_POST['a5']) : null; ?> cs_bookdemo2.php collects more information and posts to cs_bookdemo3.php, which has the same session code and variables with the addition of the fields just posted on page 2: <?php session_start(); $_SESSION['name']=!empty($_POST['name'])? htmlspecialchars($_POST['name']) : null; $_SESSION['company']=!empty($_POST['company'])? htmlspecialchars($_POST['company']) : null; $_SESSION['sector']=!empty($_POST['sector'])? htmlspecialchars($_POST['sector']) : null; $_SESSION['tel']=!empty($_POST['tel'])? htmlspecialchars($_POST['tel']) : null; $_SESSION['mob']=!empty($_POST['mob'])? htmlspecialchars($_POST['mob']) : null; $_SESSION['emai']=!empty($_POST['email'])? htmlspecialchars($_POST['email']) : null; $_SESSION['a1']=!empty($_POST['a1'])? htmlspecialchars($_POST['a1']) : null; $_SESSION['a2']=!empty($_POST['a2'])? htmlspecialchars($_POST['a2']) : null; $_SESSION['a3']=!empty($_POST['a3'])? htmlspecialchars($_POST['a3']) : null; $_SESSION['a4']=!empty($_POST['a4'])? htmlspecialchars($_POST['a4']) : null; $_SESSION['a5']=!empty($_POST['a5'])? htmlspecialchars($_POST['a5']) : null; $_SESSION['p1']=!empty($_POST['p1'])? htmlspecialchars($_POST['p1']) : null; $_SESSION['p2']=!empty($_POST['p2'])? htmlspecialchars($_POST['p2']) : null; $_SESSION['p3']=!empty($_POST['p3'])? htmlspecialchars($_POST['p3']) : null; $_SESSION['reqdate']=!empty($_POST['reqdate'])? htmlspecialchars($_POST['reqdate']) : null; $_SESSION['time']=!empty($_POST['time'])? htmlspecialchars($_POST['time']) : null; ?> Page 3 then collects more information and posts to cs_bookdemo4.php, which contains the email code: <?php session_start(); $_SESSION['name']=!empty($_POST['name'])? htmlspecialchars($_POST['name']) : null; $_SESSION['company']=!empty($_POST['company'])? htmlspecialchars($_POST['company']) : null; $_SESSION['sector']=!empty($_POST['sector'])? htmlspecialchars($_POST['sector']) : null; $_SESSION['tel']=!empty($_POST['tel'])? htmlspecialchars($_POST['tel']) : null; $_SESSION['mob']=!empty($_POST['mob'])? htmlspecialchars($_POST['mob']) : null; $_SESSION['emai']=!empty($_POST['email'])? htmlspecialchars($_POST['email']) : null; $_SESSION['a1']=!empty($_POST['a1'])? htmlspecialchars($_POST['a1']) : null; $_SESSION['a2']=!empty($_POST['a2'])? htmlspecialchars($_POST['a2']) : null; $_SESSION['a3']=!empty($_POST['a3'])? htmlspecialchars($_POST['a3']) : null; $_SESSION['a4']=!empty($_POST['a4'])? htmlspecialchars($_POST['a4']) : null; $_SESSION['a5']=!empty($_POST['a5'])? htmlspecialchars($_POST['a5']) : null; $_SESSION['p1']=!empty($_POST['p1'])? htmlspecialchars($_POST['p1']) : null; $_SESSION['p2']=!empty($_POST['p2'])? htmlspecialchars($_POST['p2']) : null; $_SESSION['p3']=!empty($_POST['p3'])? htmlspecialchars($_POST['p3']) : null; $_SESSION['reqdate']=!empty($_POST['reqdate'])? htmlspecialchars($_POST['reqdate']) : null; $_SESSION['time']=!empty($_POST['time'])? htmlspecialchars($_POST['time']) : null; $_SESSION['location']=!empty($_POST['location'])? htmlspecialchars($_POST['location']) : null; $_SESSION['source']=!empty($_POST['source'])? htmlspecialchars($_POST['source']) : null; $_SESSION['notes']=!empty($_POST['notes'])? htmlspecialchars($_POST['notes']) : null; mail('myemail@address.co.uk','** New Product Demo Request ($reqdate) (Time: $time) **',"A website visitor has submitted the following demonstration request:-\n\n Requested Date: $reqdate \n Requested Time Slot: $time \n Demo Location: $location \n \n\n Their Details:-\n \n Their Name: $name \n Company Name: $company \n Job Position: $job \n Sector: $sector \n\n \n Telephone: $tel \n Mobile: $mobile \n Email: $email \n \n Company Address:-\n $a1 \n $a2 \n $a3 \n $a4 \n $a5 \n \n Source: $source \n \n Product Details:-\n \n 1: $p1 \n 2: $p2 \n 3: $p3 \n \n Additional Notes:-\n \n $notes \n Form sent from IP address: $ip","From: CenturySoftware.co.uk <website@centurysoftware.co.uk>") or die("Unable to send form data, please contact us"); ?> The resulting email output is everything above but excludes any data entered by the user. What am I doing wrong? I have also tried using hidden fields and populating these fields with php, and getting that particular page to "pass on" the variables again to the next page but I'm having no luck. Any guidance would be appreciated. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/166797-solved-session-help-passing-variables-between-pages/ Share on other sites More sharing options...
rhodesa Posted July 21, 2009 Share Posted July 21, 2009 you are doing 2 things wrong..... 1) On cs_bookdemo3.php (nd subsequent pages) you have something like this: $_SESSION['name']=!empty($_POST['name'])? htmlspecialchars($_POST['name']) : null; But there shouldn't be a form element of 'name', since that was on cs_bookdemo.php and was posted to cs_bookdemo2.php. So, when you get to this step, it will take whatever cs_bookdemo2.php set and overwrite it with null. 2) You have the values stored in $_SESSION, but you are trying to access them with directly. Example: $_SESSION['reqdate']=!empty($_POST['reqdate'])? htmlspecialchars($_POST['reqdate']) : null; .... Requested Date: $reqdate \n You need to use the session variable to read it: Requested Date: {$_SESSION['reqdate']} \n Quote Link to comment https://forums.phpfreaks.com/topic/166797-solved-session-help-passing-variables-between-pages/#findComment-879530 Share on other sites More sharing options...
ignace Posted July 21, 2009 Share Posted July 21, 2009 http://www.phpfreaks.com/forums/index.php/topic,261112.msg1230646.html#msg1230646 Quote Link to comment https://forums.phpfreaks.com/topic/166797-solved-session-help-passing-variables-between-pages/#findComment-879531 Share on other sites More sharing options...
skot Posted July 21, 2009 Author Share Posted July 21, 2009 1) On cs_bookdemo3.php (nd subsequent pages) you have something like this: $_SESSION['name']=!empty($_POST['name'])? htmlspecialchars($_POST['name']) : null; But there shouldn't be a form element of 'name', since that was on cs_bookdemo.php and was posted to cs_bookdemo2.php. So, when you get to this step, it will take whatever cs_bookdemo2.php set and overwrite it with null. Hi Rhodesa. Thanks for your help. I have removed 'null' from the code but I receive a php error. The code is now: <?php session_start(); $_SESSION['name']=!empty($_POST['name'])? htmlspecialchars($_POST['name']); $_SESSION['company']=!empty($_POST['company'])? htmlspecialchars($_POST['company']); $_SESSION['sector']=!empty($_POST['sector'])? htmlspecialchars($_POST['sector']); $_SESSION['tel']=!empty($_POST['tel'])? htmlspecialchars($_POST['tel']); $_SESSION['mob']=!empty($_POST['mob'])? htmlspecialchars($_POST['mob']); $_SESSION['email']=!empty($_POST['email'])? htmlspecialchars($_POST['email']); $_SESSION['a1']=!empty($_POST['a1'])? htmlspecialchars($_POST['a1']); $_SESSION['a2']=!empty($_POST['a2'])? htmlspecialchars($_POST['a2']); $_SESSION['a3']=!empty($_POST['a3'])? htmlspecialchars($_POST['a3']); $_SESSION['a4']=!empty($_POST['a4'])? htmlspecialchars($_POST['a4']); $_SESSION['a5']=!empty($_POST['a5'])? htmlspecialchars($_POST['a5']); ?> But when I go to page 2 I get this error:- Parse error: syntax error, unexpected T_VARIABLE in /home/bridgey/public_html/cs_bookdemo2.php on line 4 Quote Link to comment https://forums.phpfreaks.com/topic/166797-solved-session-help-passing-variables-between-pages/#findComment-879555 Share on other sites More sharing options...
rhodesa Posted July 21, 2009 Share Posted July 21, 2009 You want to use: if(!empty($_POST['name'])) $_SESSION['name'] = htmlspecialchars($_POST['name']); Quote Link to comment https://forums.phpfreaks.com/topic/166797-solved-session-help-passing-variables-between-pages/#findComment-879556 Share on other sites More sharing options...
skot Posted July 21, 2009 Author Share Posted July 21, 2009 Works perfect You're amazing Thank you Quote Link to comment https://forums.phpfreaks.com/topic/166797-solved-session-help-passing-variables-between-pages/#findComment-879576 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.