passing variables to another script

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

Post Reply
jennagz
Forum Newbie
Posts: 3
Joined: Fri Apr 04, 2003 3:24 pm
Location: Florida

passing variables to another script

Post by jennagz »

I can't find any other problem related to mine with a solution so any answer is much appreciated.

I am able to pass the values from the form to the first php script. This script e-mails the form contents in html. It displays the values fine.

In the html message the person receives, there is a form action calling another php script. I cannot get the values in the e-mail to pass along to the next php script. I've tried hidden fields and sessions (although I may not be using sessions properly as I am new to php) and nothing seems to be working. Here is a simple example:

form:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Form Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form name="test" method="post" action="script1.php">
<p>
<input name="check" type="radio" value="Here">
Check Here</p>
<p>
<input name="check" type="radio" value="Or">
Or Here</p>
<p>Enter Text:
<input name="text" type="text" id="text">
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
<p>&nbsp; </p>
</form>
</body>
</html>

script1.php

<?php

$htmlmsg =
"<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=Content-Type content=text/html; charset=iso-8859-1>
</head>

<body>
<form name=form1 method=post action=http://10.10.10.10/protect/script2.php>
<p>$check</p>
<p>$text</p>
<p>
<input type=submit name=Submit value=Submit>
</p>
<p>&nbsp; </p>
</form>
</body>
</html>
";

$headers = "MIME-Version: 1.0";
$headers = "Content-Type: text/html; charset=iso-8859-1";

mail("user@mail.com", "Test", $htmlmsg, $headers);

echo "Thanks!";

?>

script2.php

<?php

$htmlmsg =
"<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN>
<html>
<head>
<title>test 2</title>
<meta http-equiv=Content-Type content=text/html; charset=iso-8859-1>
</head>

<body>
<form name=form1 method=post action=script3.php>
<input type=hidden name=check value=\"<? echo $check ?>\">
<p>$text</p>
<p>$pass</p>
<p>
<input type=submit name=Submit value=Submit>
</p>
<p>&nbsp; </p>
</form>
</body>
</html>
";

$headers = "MIME-Version: 1.0";
$headers = "Content-Type: text/html; charset=iso-8859-1";

mail("user@mail.com", "test 2", $htmlmsg, $headers);

echo "Thanks!";

?>

Anyway, then this script would e-mail the values to the next person. I tried using the hidden field for one variable to test. I also tried (not shown) to print them outside of the $htmlmsg variable, but that didn't work either.

Thanks.
User avatar
Kriek
Forum Contributor
Posts: 238
Joined: Wed May 29, 2002 3:46 am
Location: Florida
Contact:

Predefined Variables

Post by Kriek »

Just assign your variables being passed.
See $_POST, $_GET and $_REQUEST (Predefined Variables)

Code: Select all

<?php 
$var=$_POST['var'];

// depending on method

$var=$_GET['var'];
?>
jennagz
Forum Newbie
Posts: 3
Joined: Fri Apr 04, 2003 3:24 pm
Location: Florida

Post by jennagz »

Thank you for your quick response. I had already tried that and the problem that I'm encountering is any php within $htmlmsg = " "; is not being read. I can't get a variable to pass even using <?php echo ($var); ?>

It's like anything inside $htmlmsg will not be looked at except for the html.
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

php not showing

Post by phpScott »

If this is email being sent to some one's email client and that is where they are viewing the body of the message then the php will not show because there email client would have know idea what php is.
What has to happen I think is that the action on the form has to be a call back to your site like
http://www.yoursite.com/replyemail/scri ... ar2=value2

you will probably have to use javascript or something to create the url

I will also recomend doing some testing on the values that are recieved in your script2.php to make sure nothing dangerous is being passed through.

I have done something simillar in a text file with a standared anchor link but I think the same idea should work.

phpScott
Jim
Forum Contributor
Posts: 238
Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas

Post by Jim »

Don't know that it's incredibly important, but just to warn you...

You defined $headers twice in your code.

Code: Select all

$headers = "MIME-Version: 1.0"; 
                       $headers = "Content-Type: text/html; charset=iso-8859-1";
The code will take the last version of the headers variable and use it in the script. Might want to:

a.) Put that header info on the same line

or

b.) Name the second variable something other than '$headers'.
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

more to jims post

Post by phpScott »

or you can concatinate the variables like so

Code: Select all

$headers = "MIME-Version: 1.0";
$headers .= " Content-Type: text/html; charset=iso-8859-1";
notice the dot. period, . thing that will then put the variables together, be careful of spacing though when doing this.

phpScott
jennagz
Forum Newbie
Posts: 3
Joined: Fri Apr 04, 2003 3:24 pm
Location: Florida

Post by jennagz »

Thank you everyone for responding. I appreciate it.
Post Reply