Page 1 of 2
Error parsing variables via mail.php page..??
Posted: Sun Aug 06, 2006 5:47 am
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

Posted: Sun Aug 06, 2006 6:37 am
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>'; */
Posted: Sun Aug 06, 2006 6:45 am
by bokehman
Or like this:
Code: Select all
session_start();
foreach($_POST as $k => $v)
{
$_SESSION[$k] = $v;
}
Posted: Sun Aug 06, 2006 6:54 am
by s.dot
Hm.... that could bring up a topic of security..... but yeah that works, too. =]
Posted: Sun Aug 06, 2006 6:55 am
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
to show the actual info?
Posted: Sun Aug 06, 2006 6:55 am
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

Posted: Sun Aug 06, 2006 7:00 am
by bokehman
astions wrote:You of all people
What's special about me? Can't I suggest something insecure?
Posted: Sun Aug 06, 2006 7:05 am
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...
Posted: Sun Aug 06, 2006 7:32 am
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
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="
">
and then on the confirm page
- however this doesnt work, it shows $name
any ideas?
Posted: Sun Aug 06, 2006 8:10 am
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

Posted: Sun Aug 06, 2006 8:24 am
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
Posted: Sun Aug 06, 2006 8:31 am
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 ?>">
Posted: Sun Aug 06, 2006 8:31 am
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
Posted: Sun Aug 06, 2006 9:07 am
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>';
*/
Posted: Sun Aug 06, 2006 10:33 am
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...