Error parsing variables via mail.php page..??

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
munkynpunky
Forum Newbie
Posts: 8
Joined: Sun Aug 06, 2006 5:34 am
Location: Kings Lynn, UK

Error parsing variables via mail.php page..??

Post by munkynpunky »

Hi Guys,

Im completely new to the forum, but have some knowledge about php.

I am trying to pass certain variables, (basically a multi-page form).

page one has user details, page two has product details, There is a php sendmail page hidden from the user then it goes to a confirm page, then using some of the variables off page one and page two show some info on page three.

What is the best way because at the moment, i am using POST / GET but they seem to be having a problem, because after page two, there is a sendmail.php page hidden from users, which then redirects to the confirm page.

I have tried to use sessions but without much luck.

So, what do you think i can/should use?

Thanks in advance

Drew :)
Last edited by munkynpunky on Sun Aug 06, 2006 5:47 pm, edited 1 time in total.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Sessions are the best way to go.

It's quite easy. After step one was submitted, store the result in the session like so:

Code: Select all

session_start();

$_SESSION['firstName'] = $_POST['firstName'];
$_SESSION['lastName'] = $_POST['lastName'];
//etc..


/* See what ya got in your session
echo '<pre>';
print_r($_SESSION);
echo '</pre>'; */
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post by bokehman »

Or like this:

Code: Select all

session_start();
foreach($_POST as $k => $v)
{
	$_SESSION[$k] = $v;
}
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Hm.... that could bring up a topic of security..... but yeah that works, too. =]
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
munkynpunky
Forum Newbie
Posts: 8
Joined: Sun Aug 06, 2006 5:34 am
Location: Kings Lynn, UK

Post by munkynpunky »

So at the top of page two add

Code: Select all

session_start();

$_SESSION['firstName'] = $_POST['firstName'];
$_SESSION['lastName'] = $_POST['lastName'];
//etc..
stupid question, do i then just need to

Code: Select all

echo $_SESSION['firstName']
to show the actual info?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

bokehman wrote:Or like this:

Code: Select all

session_start();
foreach($_POST as $k => $v)
{
	$_SESSION[$k] = $v;
}
You of all people should know better than to recommend something like that :?
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post by bokehman »

astions wrote:You of all people
What's special about me? Can't I suggest something insecure?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

bokehman wrote:
astions wrote:You of all people
What's special about me? Can't I suggest something insecure?
What is special about you? = You are far more knowledgeable than most individuals in this forum.
Can't I suggest something insecure = Sure if you want to, but hence the comment.. You of all people...
User avatar
munkynpunky
Forum Newbie
Posts: 8
Joined: Sun Aug 06, 2006 5:34 am
Location: Kings Lynn, UK

Post by munkynpunky »

On the second page, and the confirm page i put this

<head>

Code: Select all

session_start(); 

$_SESSION['name'] = $_POST['name']; 
$_SESSION['address'] = $_POST['address'];
$_SESSION['address2'] = $_POST['address2']; 
$_SESSION['town'] = $_POST['town'];
$_SESSION['county'] = $_POST['county'];
$_SESSION['postcode'] = $_POST['postcode'];
$_SESSION['phone'] = $_POST['phone'];
$_SESSION['hear'] = $_POST['hear'];
$_SESSION['recommend'] = $_POST['recommend'];

$name = $_SESSION['name'];
$address = $_SESSION['address'];
$address2 = $_SESSION['address2'];
$town = $_SESSION['town'];
$county = $_SESSION['county'];
$postcode = $_SESSION['postcode'];
$phone = $_SESSION['phone'];
$hear = $_SESSION['hear'];
$recommend = $_SESSION['recommend'];
</head>

so to check it, on the second page (after they add their info) i added this

Code: Select all

<? echo "$name" ; ?>
this shows what they type in, so it works... now on the form to pass to the confirm page:

<input type="hidden" name="name" value="

Code: Select all

<? echo '$name'; ?>
">

and then on the confirm page

Code: Select all

<? echo "$name"; ?>
- however this doesnt work, it shows $name

any ideas?
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

instead of putting everything in hidden fields and submitting the form, why not just put

Code: Select all

session_start();
print_r($_SESSION);
on the last page there and see what comes up. and the reason its not working for you right now is because when you submit the form, $name does not exist, but $_POST['name'] does exist ;)
User avatar
munkynpunky
Forum Newbie
Posts: 8
Joined: Sun Aug 06, 2006 5:34 am
Location: Kings Lynn, UK

Post by munkynpunky »

shiznatix wrote:instead of putting everything in hidden fields and submitting the form, why not just put
....
on the last page there and see what comes up. and the reason its not working for you right now is because when you submit the form, $name does not exist, but $_POST['name'] does exist ;)

Code: Select all

session_start(); 

$_SESSION['name'] = $_POST['name']; 
//etc

$name = $_SESSION['name']; 
//etc
I thought that by putting that above, that meant that $name = $session['name'] = $_POST['name'];

so $name is known?

Thanks for the help so far, nearly there!!

Drew
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post by bokehman »

Code: Select all

<input type="hidden" name="name" value="<?php echo '$name'; ?>">
Get rid of any quotes around $name:

Code: Select all

<input type="hidden" name="name" value="<?php echo $name ?>">
User avatar
munkynpunky
Forum Newbie
Posts: 8
Joined: Sun Aug 06, 2006 5:34 am
Location: Kings Lynn, UK

Post by munkynpunky »

[quote="shiznatix"]instead of putting everything in hidden fields and submitting the form, why not just put

Code: Select all

session_start();
print_r($_SESSION);
When i do that, i get this message.

Array
(
)

$name
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

Which means there's nothing in the $_SESSION array.

A simplified example:
index.php:

Code: Select all

session_start();

if(isset($_POST['submit'])) {
  $_SESSION['name'] = $_POST['name'];
  $_SESSION['age'] = $_POST['age'];

  echo 'Click <a href="other.php">here</a> to go to another page.';
} else {
  echo '<form action="index.php" method="post">
  <input type="text" name="name" />
  <input type="text" name="age" />
  <input type="submit" name="submit" />';
}
other.php

Code: Select all

session_start();

echo $_SESSION['name'];
echo $_SESSION['age'];

//or you could do what shiz suggested to test it
/*
echo '<pre>';
print_r($_SESSION);
echo '</pre>';
*/
User avatar
munkynpunky
Forum Newbie
Posts: 8
Joined: Sun Aug 06, 2006 5:34 am
Location: Kings Lynn, UK

Post by munkynpunky »

jayshields wrote:
other.php

Code: Select all

session_start();

echo $_SESSION['name'];
echo $_SESSION['age'];

//or you could do what shiz suggested to test it
/*
echo '<pre>';
print_r($_SESSION);
echo '</pre>';
*/
i do that but i get array()...

im confused now...
Post Reply