Jump to content

How to pass value from one page to other inphp ???


dimple

Recommended Posts

Hi,

Can any one one tell me how to pass a text box (Session variable) value from one form to another using submit button. I tried it , but there is a problem like i have to press enter first then the value pass on nsession then i can go to next page but i dnt want these type of problems in my project.

Kindly help me here or mail me to

[email protected]

 

Thanx.

You seem to be confused between concepts here. Passing a variable between forms using the submit button is all to do with using the $_POST and $_GET superglobal arrays. $_SESSIONS is another superglobal array which is generally used to maintain a value during that users visit to a site, regardless of the page they are on.

 

Page1.php

<form action ="Page2.php" method="post">
<input type="text" name="username" />
<input type="submit" value="Send" />
</form>

 

Page2.php

<form action ="Page2.php" method="post">
<input type="text" name="username" value="<?php echo $_POST['username']; ?> />
<input type="submit" value="Send" />
</form>

to get to the next page, a button of some sort needs to be pressed... I assume....

 

if thats the case, then the best way is to POST the info to the next page.

 

you can store the info in a session like below;

 

session_start();
$_SESSION['textarea']= ['textarea'];
header( "Location: nextpage.php" );

 

then on the top of the next page....

 

<?php
//start the session
session_start();

//check to make sure the session variable is registered
if(isset($_SESSION['textarea'])){
$text=$_SESSION['textarea'];
}
else{
//the session variable isn't registered, send them to the error page
header( "Location: errorpage.php" );
}
?>

 

this saves your 'textarea' info into a variable called $text

I m sure session variable is registered bcz after press the enter button it take its value then i click on next link for next page & there i use session variable in my query to filter data. Its mean the session is registered but the problem is how to put value in session without press enter key.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.