Jump to content

Recommended Posts

I want to carry a variable through three php pages.

 

the variable is the first_name of the visitor which is entered through a form in an textfield.

the form calls action to another php, where I am able to extract the variable by the use of the $_POST['first_name']

 

But that second php calls another php file called upload.php, where I want to use that variable again. But till the third php file I have lost it.

 

I don't want to get in the complicated world of sessions. I heard that i can still carry it through separate pages through the use of a form.... how can i achieve that without showing anything on screen.

Link to comment
https://forums.phpfreaks.com/topic/123824-carrying-variables-over-multiple-pages/
Share on other sites

I want to carry a variable through three php pages.

 

the variable is the first_name of the visitor which is entered through a form in an textfield.

the form calls action to another php, where I am able to extract the variable by the use of the $_POST['first_name']

 

But that second php calls another php file called upload.php, where I want to use that variable again. But till the third php file I have lost it.

 

I don't want to get in the complicated world of sessions. I heard that i can still carry it through separate pages through the use of a form.... how can i achieve that without showing anything on screen.

 

Simply use a form with hidden inputs:

Page 1 -

<form action="page2.php" method="post">
<input type="text" name="user" />
.
.
.
</form>

 

Page 2 -

<?php
   $user = $_POST['user'];
   .
   .
   .
?>

<form action="page3.php" method="post">
<input type="hidden" name="user" value="<?php echo $user; ?>" />
.
.
.
</form>

 

Page 3 -

<?php
   $user = $_POST['user'];
?>

Now that I see the code, it seem that I will have trouble implementing that technique, cause the third file is called through a flash/javascript file and its integrated in a way where I won't be able to use forms. Sorry for that.

 

I guess my only option is to use sessions. For testing purposes I have created three files which carry a variable over, but it does not seem to work at my end.

 

page1.php

<form id="user" method="post" action='page2.php'>
    <fieldset >
    <legend>User Information</legend>
<table width="650">
    <tr><td width="100" align="right">
    First Name</td>
    <td align="left">
    <input name="first_name" type="text" class="formtextfield"/></td></tr>
<input name="I Accept" type="submit" /></td></tr></table>
    </fieldset>
    </form>

 

page2.php

<?php
session_start();
$first_name = $_SESSION['first_name'];
?>
<form action="page3.php" method="post">
<input name="Submit" type="submit">

</form>

 

page3.php

<?php
session_start();
$first_name = $_SESSION['first_name'];
echo "This is my".$first_name;
?>

 

Help will be appreciated.

 

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.