Reply
Trying to pass a PHP variable from one page (with a form) to another
Old 01-16-2009, 07:53 AM Trying to pass a PHP variable from one page (with a form) to another
Average Talker

Posts: 18
Name: sadssa
Trades: 0
Hi,

i've written a form which sends what the user writes into the boxes to other web page.

In the same time, i would like to send to the receiving web page a PHP variable.

This is my try but it doesn't work. Any idea?



PHP Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head><title></title>

<style type="text/css" media=all>

</style>
</head>

<body>


<form method="POST" action="http://localhost/red_social/resultado_busqueda.php">

<?php

$var
="Hola";

?>

<input type="text" name="nombre"><br>
<input type="text" name="apellidos"><br>
<input type="text" name="email"><br>
<input type="text" name="telefono"><br>
<input type="text" name="domicilio"><br>
<input type="text" name="fechanacimiento"><br>

<input type="submit" name="Buscar"><br>

<input name="flag" type="hidden" id="flag" value="<?php echo $_POST['flag'?>">



</form>


</body>

</html>

PHP Code:
<html>
<head><title></title>

<style type="text/css" media=all>

</style>
</head>

<body>

<?php

echo $_GET["flag"];

?>

</body>

</html>
tirengarfio is offline
Reply With Quote
View Public Profile
 
 
When You Register, These Ads Go Away!
Old 01-16-2009, 08:28 AM Re: Trying to pass a PHP variable from one page (with a form) to another
King Spam Talker

Posts: 1,412
Trades: 0
Quote:
<form method="POST" action="resultado_busqueda.php">
is the reciever of the form information

On that page is where the php code should be placed. I usually have a debug routine to make sure it is getting there which I // remark out or remove when I am done. In your case my debug would look like.

PHP Code:
echo $_POST['whatever was submitted on the form']; //debug only
echo "br />; //debug only
echo $_post[the next item];//debug only 
And I continue with the echos until I know I have all the submitted data getting to the right page and then I do whatever I want with it.

Once I get the sender and the reciever both working I incorporate them into one script or page but that topic is a little more advanced then you are ready for this morning.
__________________
Colbyt

Last edited by colbyt; 01-16-2009 at 08:29 AM..
colbyt is offline
Reply With Quote
View Public Profile
 
Old 01-16-2009, 08:33 AM Re: Trying to pass a PHP variable from one page (with a form) to another
stoot98's Avatar
Ultra Talker

Posts: 427
Name: Stuart
Location: Glasgow, Scotland
Trades: 0
You are trying to print the variable from the $_GET array when you are POSTing the form and so it should be accessed from the $_POST array.

PHP Code:
<html>
<head><title></title>

<style type="text/css" media=all>

</style>
</head>

<body>

<?php

echo $_POST["flag"];

?>

</body>

</html>
stoot98 is offline
Reply With Quote
View Public Profile
 
Old 01-16-2009, 08:53 AM Re: Trying to pass a PHP variable from one page (with a form) to another
Average Talker

Posts: 18
Name: sadssa
Trades: 0
Quote:
Originally Posted by stoot98 View Post
You are trying to print the variable from the $_GET array when you are POSTing the form and so it should be accessed from the $_POST array.

PHP Code:
<html>
<head><title></title>

<style type="text/css" media=all>

</style>
</head>

<body>

<?php

echo $_POST["flag"];

?>

</body>

</html>
I tried that but it doesn't work...
tirengarfio is offline
Reply With Quote
View Public Profile
 
Old 01-16-2009, 10:07 AM Re: Trying to pass a PHP variable from one page (with a form) to another
stoot98's Avatar
Ultra Talker

Posts: 427
Name: Stuart
Location: Glasgow, Scotland
Trades: 0
I would suggest checking the source of the form's page to make sure the hidden field is populated with a value from the $_POST['flag'] variable which from your code isnt likely to be set. You might want to use $_GET['flag'] if it is being passed from a link on the source page.
stoot98 is offline
Reply With Quote
View Public Profile
 
Old 01-19-2009, 08:28 PM Re: Trying to pass a PHP variable from one page (with a form) to another
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
Converting Video For YouTube
Posts: 2,556
Name: Keith Marshall
Location: West Hartford, CT
Trades: 0
I think what you are trying to do is:

Page 1:
PHP Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head><title></title>
<style type="text/css" media=all>
</style>
</head>
<body>

<form method="POST" action="http://localhost/red_social/resultado_busqueda.php">
<?php
$var
="Hola";
?>
<input type="text" name="nombre"><br>
<input type="text" name="apellidos"><br>
<input type="text" name="email"><br>
<input type="text" name="telefono"><br>
<input type="text" name="domicilio"><br>
<input type="text" name="fechanacimiento"><br>
<input type="submit" name="Buscar"><br>
<input name="flag" type="hidden" id="flag" value="<?php echo htmlentities($var?>">
 
</form>

</body>
</html>
Page 2:
PHP Code:
<html>
<head><title></title>
<style type="text/css" media=all>
</style>
</head>
<body>
<?php
echo htmlentities($_POST["flag"]);
?>
</body>
</html>
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Trying to pass a PHP variable from one page (with a form) to another
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 



Page generated in 0.20157 seconds with 13 queries