473,396 Members | 2,039 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

passing variables with forms

Hi. I'm struggling to pass variables through various web forms.

On my first php page I have tried to use:

Expand|Select|Wrap|Line Numbers
  1.  
  2. <input type="hidden" name="email" value="<$php $_POST["email"]; print "$email"; ?>" />
  3.  
  4.  
I am passing four variables from my first html page to the first php page. From here I want to pass the variables to another html page and then finally to the last php page.

So basically the process is as follows:

details.html > details.php > payment_details.html > payment_details.php

On the final php page(payment_details.php I plan to use the php mail() function to email the variables to a customer and echo a confirmation message to the customer telling them of the details being sent but I can't seem to find a way of passing the variables through continuous pages.

Any feedback would be much appreciated.

Thanks,

Jordan
Dec 21 '10 #1

✓ answered by AutumnsDecay

Your variables are empty, by the looks of your code. Your variables are $_SESSION['rideselection'], not $rideselection.

The best thing to do would be to:

Expand|Select|Wrap|Line Numbers
  1. $rideselection = $_SESSION['rideselection'];
And so on, for all your session variables before you insert them into the message part of your email.

Also, you're putting your variables within a string, which wont work. Change your $message= to:

Expand|Select|Wrap|Line Numbers
  1. $message="Thank you for booking with us.\n\nYou have chose to ride: " . $rideselection . "\n\nSeatnumber: " . $seatnumber . "\n\n At: " . $time;
  2.  

10 1545
johny10151981
1,059 1GB
Expand|Select|Wrap|Line Numbers
  1. <input type="hidden" name="email" value="<$php $_POST["email"]; print "$email"; ?>" />
  2.  
in this line there is something strange. lets break your line like below and see what we have
Expand|Select|Wrap|Line Numbers
  1. <input type="hidden" name="email" value="<$php
  2.  $_POST["email"]; 
  3.  print "$email"; 
  4. ?>" />
  5.  
now take a closer look line 2 is doing nothing. on line 3 you are printing $email I believe this is empty.

you better try this on line 2

Expand|Select|Wrap|Line Numbers
  1. $email=$_POST['email'];
  2.  
then print. you might reach somewhere.
Dec 22 '10 #2
Thanks for the reply johny10151981 much appreciated but that didn't seem to work either
Dec 22 '10 #3
JKing
1,206 Expert 1GB
You should consider using sessions.
Dec 22 '10 #4
In what way would I use sessions JKing? would I use sessions for each variable name?
Dec 23 '10 #5
JKing
1,206 Expert 1GB
To store and pass your variables. It is a common practice when dealing with shopping carts or ecommerce sites. A session is temporary data stored on the server that can be accessed throughout the life of the session and is available to all pages.

Google php sessions. Several tutorials should come up. Have a read through them as I am sure they will explain them better and with more depth than I would.
Dec 23 '10 #6
I've figured out how to use sessions however I am having problems putting the variables into the php mail function.

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php
  3.  
  4. session_start();
  5.  
  6. print $_SESSION['email'];
  7. print "<br />";
  8. print $_SESSION['seatnumber'];
  9. print "<br />";
  10. print $_SESSION['time'];
  11. print "<br />";
  12. print $_SESSION['rideselection'];
  13.  
  14. $to= $_POST['email'];
  15. $subject="Ticket Confirmation";
  16. $message="Thank you for booking with us.\n\nYou have chose to ride: $rideselection\n\nSeatnumber: $seatnumber\n\n At: $time";
  17. $from="ed345@bolton.co.uk";
  18. $headers="From: ed345@bolton.co.uk";
  19. mail($to,$subject,$message,$headers);
  20.  
  21.  
Dec 26 '10 #7
AutumnsDecay
170 100+
Your variables are empty, by the looks of your code. Your variables are $_SESSION['rideselection'], not $rideselection.

The best thing to do would be to:

Expand|Select|Wrap|Line Numbers
  1. $rideselection = $_SESSION['rideselection'];
And so on, for all your session variables before you insert them into the message part of your email.

Also, you're putting your variables within a string, which wont work. Change your $message= to:

Expand|Select|Wrap|Line Numbers
  1. $message="Thank you for booking with us.\n\nYou have chose to ride: " . $rideselection . "\n\nSeatnumber: " . $seatnumber . "\n\n At: " . $time;
  2.  
Dec 26 '10 #8
Samishii23
246 100+
When dealing with $_SESSION and $_POST variables, the bracketed name ['name'] is an associative array name. The ['name'] is the identifier of the array item. Where as $_POST['name'] is the variable. Not $name.

$name is completely separate from $_POST['name'] as mentioned above. Instead of doing this:
Expand|Select|Wrap|Line Numbers
  1. $name = $_POST['name'];
  2. print $name;
Save some overhead and simply do:
Expand|Select|Wrap|Line Numbers
  1. print $_POST['name'];
Where as, the easier way to do this:
Expand|Select|Wrap|Line Numbers
  1. $message="Thank you for booking with us.\n\nYou have chose to ride: $rideselection\n\nSeatnumber: $seatnumber\n\n At: $time";
Try:
Expand|Select|Wrap|Line Numbers
  1. $message="Thank you for booking with us.\n\nYou have chose to ride: ". $rideselection ."\n\nSeatnumber: ". $seatnumber. "\n\n At: ". $time;
This line seperates the string from the variables, making it easier to read in an editor (atleast one with the color coding)
Dec 26 '10 #9
Thanks guys for your help it worked! The only problem I have now is when the user submits the details a message saying "Message delivery failed..." appears even though an email is sent with the appropriate details which is confusing. Here is my code...

Expand|Select|Wrap|Line Numbers
  1.  
  2. $to="\nE-Mail is: ".$email;
  3. $subject="Ticket Confirmation";
  4. $message="Thank you for booking with us.\n\nYou have chose to ride: ".$rideselection. "\n\nSeatnumber: ".$seatnumber. "\n\n At: ".$time;
  5. $from="ed345@bolton.cu.uk";
  6. $headers="From: ed345@bolton.co.uk";
  7.  
  8. mail($to,$subject,$message,$from,$headers);
  9.  
  10.  
  11. if (mail($to,$subject,$message,$from,$headers))
  12.  
  13.     {
  14.  
  15.            echo("Message successfully sent!");
  16.  
  17.     }
  18.  
  19.   else
  20.  
  21.       {
  22.  
  23.            echo("Message delivery failed...");
  24.  
  25.       }
  26.  
  27.  
That is my code and everything is in working order as when I submit my own details for testing purposes, an e-mail is sent to my email server yet I get the error message saying "Message delivery failed..."
Dec 28 '10 #10
Samishii23
246 100+
Your sending two mails?
After looking at PHP.net's function reference. Your parameters are incorrect.
Expand|Select|Wrap|Line Numbers
  1. bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]]
Dec 28 '10 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: lawrence | last post by:
Those of you with backgrounds with the C language will laugh at my mistake, but those of you, like myself, who deal mostly with PHP should be warned about passing variables as references -...
7
by: Matthew Robinson | last post by:
i read a tutorial the other day on passing variables between php pages using a html form and setting the action to the php page to parse, can anybody see anything wrong with the code below? the...
2
by: Chieko Kuroda | last post by:
Hello all, I would like to learn the syntax for passing variables that I retreived from a database to a second asp page. Currently, I'm using: Response.Write "<tr><td>&nbsp;</td><td><Font size=...
1
by: Consuelo Guenther | last post by:
Hello, I am having problems with passing variables between pages. I have the following: First asp page has the function: -----------------------------------------------------------------------...
7
by: Khai | last post by:
First off, yes, I understand the crapload of tutorials out there, (well, rather, I understand there /are/ a crapload of tutorials out there), the problem is my comprehension. I'm trying to pass...
3
by: jsdeveloper | last post by:
Hi, I just started programming in javascript, and I'm having a problem passing variables between javascript and asp code in .asp page. Can you please help? I've given the sample code below. ...
1
satterfieldben
by: satterfieldben | last post by:
I have a newbie question about passing variables between functions. I am wanting to use a drop down box to select a value. Then base on which was selected, it would create a variable and I would call...
5
by: Shawn Northrop | last post by:
test.php: <?php $d=$_GET; echo $d; ?> when i go to www....com/test.php?data=1 nothing happens.
6
by: coool | last post by:
Hi :) anyone knows how can I send variables from a php page to a form - i need to fill the form with these variables ? maybe using (the process of passing variables to other pages - through...
6
BezerkRogue
by: BezerkRogue | last post by:
This is the most fundamental action I am sure, but I can't seem to make it happen. I am familiar with passing variables in ASP. But that doesn't seem to be the preferred method in .NET. I have...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.