Jump to content

[SOLVED] Help Using session across multiple pages


Pjack125

Recommended Posts

I am rather new to php and have to use it for a project. and I am having issue passing session value across multiple pages.

 

in page one i have a simple for

 

page1.php

------------------------

 

<html>
<head>
</head>
Body
<form id="form1" name="form1" method="post" action="page2.php">
<input name="PName" type='text' class="style9" id="PName" />
  <textarea name="Description" id="textarea" cols="45" rows="5"></textarea>
<input type="submit" name="button" id="button" value="Next>>" />
</form>
</body>
</html>

in the second page I have the following

<?php
session_start();
$PName = $_POST['PName']; 
$Description = $_POST['Description']; 
//setting the sessions I know the above was  was probably unnecessary but that's how i have it currenlty
$_SESSION['PName'] = $PName; 
$_SESSION['PDesc'] = $Description;
?>
<html>
<head>
</head>
Body
<form id="form1" name="form1" method="post" action="page3.php">
<input name="Phone" type='text' class="style9" id="Phone" />
  <textarea name="Bio" id="bio" cols="45" rows="5"></textarea>
<input type="submit" name="button" id="button" value="Next>>" />
</form>
</body>
</html>

Finally on page four i want to retrieve data from page1.php

but i can't figure it out.

what i have for page3.php is

<?php
session_start();
$_SESSION['PName']= $_POST['Phone']; 
$_SESSION['bio'] = $_POST['Bio']; 

echo $_SESSION['PName']; 
?>

 

I don't know what i am doing wrong is the session dying to early? or is it because i posted new information into the http header when i submit page2.php? I eventually want to carry this session througout four more pages...

 

Your help is greatly appriciated

 

 

Hi Pjack125,

please see untested example below

 

Grab from sessions

<?php
session_start();
// $_SESSION['PName']= $_POST['Phone']; //removed this would set it to nothing
//$_SESSION['bio'] = $_POST['Bio'];  //same as above
echo "<br>PName: ".$_SESSION['PName'];
echo "<br>PDesc: ".$_SESSION['PDesc'];
echo "<br>Phone: ".$_POST['Phone'];  //From Page 2

?>

 

 

or

Add the data to the form in a hidden box (not secure)

<?php
session_start();
$PName = $_POST['PName']; 
$Description = $_POST['Description']; 
?>
<html>
<head>
</head>
Body
<form id="form1" name="form1" method="post" action="page3.php">
<input name="Phone" type='text' class="style9" id="Phone" />
  <textarea name="Bio" id="bio" cols="45" rows="5"></textarea>
<input name="PName" value="<?php echo $PName; ?>" type='hidden' class="style9" />
<input name="Description" type='hidden' value="<?php echo $Description; ?>" class="style9" />
<input type="submit" name="button" id="button" value="Next>>" />
</form>
</body>
</html>

and read the post as normal

<?php
echo "<br>PName: ".$_POST['PName'];
echo "<br>PDesc: ".$_POST['Description'];
echo "<br>Phone: ".$_POST['Phone'];
?>

 

EDIT: fixed typo

make a Kernal file!

<?Php session_start();
?>
<html>
<body>
<?Php
echo "pcx=".$pcx;
switch (trim($pcx)){

//PCD Profile    
    case '10':
        include "page1.php";
        break;
    default:
        header('Location: index.htm');
        break;
}    
    exit;
  
echo "html eindig abnormaal";  
?>
        
</body>
</html>

MadTechie

you way works but i now have this Warning being displayed.

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/content/P/i/x/PixelFX/html/leWizPM.php:2) in /home/content/P/i/x/PixelFX/html/leWizPM.php on line 3

 

is it because i didn't close the session on the last page?

 

Nevermind Thanks Man it worked. Just keep forgetting the not even a white space before session start rule.

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.