Hi to all,

I have 4 pages. page1.php, page2.php, page3.php and last.php.
page 1, 2 and 3 pages have one text and submit button. The values enter by user in page1.php store in session var. and clicking on 'Submit' button. page2 shuold be open. In this page same procedure should happen. while on last page , I have to show all 3 values from all 3 pages using session. I tried it guys, but I lost values in last pages.

plz, help me. here are my pages....

//page1.php
<?php
session_start();  
$_SESSION['value'] = $_POST['value']; 

?>
<body>
<h2 align="center" style="font-size:xx-large; color:#F06">Use of Session</h2>
<form action="page2.php" method="post" id="page2" name="page2" enctype="multipart/form-data">
<table align="center" >
<tr>
<td>Enter the Value :</td>
<td><input type="text" name="value" id="value" /></td>
</tr>
<tr><td align="center"><input type="submit" name="submit" id="submit" value="submit" /></td>

</tr>
</table>
</form>
</body>

//page2.php
<?php
session_start();  
$_SESSION['value'] = $_POST['value'];

//submit = $_POST['submit'];
//if(!empty($submit))
//{
//echo "value of textbox".$_SESSION['value'];	
//}

?>
<body>
<h2>Use of Session</h2>
<form action="page3.php" method="post" id="page2" name="page2" enctype="multipart/form-data">
<table >
<tr>
<td>Enter the Value :</td>
<td><input type="text" name="value2" id="value2" /></td>
</tr>
<tr><td colspan="2">&nbsp;</td></tr>
<tr><td colspan="2">&nbsp;</td></tr>
<tr><td align="center"><input type="submit" name="submit" id="submit" value="submit" /></td>
</tr>
</table>
</form>
</body>

//page3.php

<?php
session_start();  
$_SESSION['value'] = $_POST['value'];
$_SESSION['value2'] = $_POST['value2'];
$_SESSION['value3'] = $_POST['value3'];
$submit = $_POST['submit'];
//if(!empty($submit))
//{
//echo "value of First Page :"."<br/>".$value."<br/>"."<br/>";	
//echo "value of Second Page :"."<br/>".$_SESSION['value2']."<br/>"."<br/>";	
//echo "value of Third Page :"."<br/>".$_SESSION['value3'];	
//}

?>
<body >
<h2 align="center" style="font-size:xx-large; color:#F06">Use of Session</h2>
<form action="last.php" method="post" id="page3" name="page3" enctype="multipart/form-data">
<br/>
<br/>
<br/>
<table>
<tr>
<td>Enter the Value :</td>
<td><input type="text" name="value3" id="value3" /></td>
</tr>
<tr><td align="center"><input type="submit" name="submit" id="submit" value="submit" /></td>

</tr>
</table>
</form>
</body>

//last.php

<?php
session_start();  
$_SESSION['value'] = $_POST['value'];
$_SESSION['value2'] = $_POST['value2'];
$_SESSION['value3'] = $_POST['value3'];
$submit = $_POST['submit'];
?>

<body>
<h2>Use of Session</h2>
<form action="last.php" name="last" id="last" method="post">
<table align="center" >
<tr><td>Value1</td>
<td>Value2</td>
<td>Value3</td></tr>
<tr>
<?php if(!empty($submit))
{
?>
    <td><?php echo $_SESSION['value']; ?></td>
    <td><?php echo $_SESSION['value2']; ?></td>
    <td><?php echo $_SESSION['value3']; ?></td>
<?php
}
?>
<tr><td colspan="2" align="center"><input type="submit" name="submit" value="submit" id="submit" /></tr>
</table>
</form>
</body>

Recommended Answers

All 7 Replies

last.php is taking $_POST values that to not exist in page3.php thereby overwriting the $_SESSIONS
Remove from last.php:

$_SESSION['value'] = $_POST['value'];
$_SESSION['value2'] = $_POST['value2'];
$_SESSION['value3'] = $_POST['value3'];

And your values should remain in tact.

Hi, You mean
$_SESSION = $_POST;
$_SESSION = $_POST;
$_SESSION = $_POST;
should i remove above 3 lines from page3.php

No remove the lines from last from last.php

You pasted this

//last.php

<?php
session_start();
$_SESSION['value'] = $_POST['value'];
$_SESSION['value2'] = $_POST['value2'];
$_SESSION['value3'] = $_POST['value3'];
$submit = $_POST['submit'];
?>

Those 3 lines are resetting your $_SESSION values at the top of the page making them empty because $_POST etc do not exist

I was getting ahead of myself - this is how your code should work:

//page1.php
<?php
session_start();
$_SESSION['value'] = $_POST['value'];

?>
<body>
<h2 align="center" style="font-size:xx-large; color:#F06">Use of Session</h2>
<form action="page2.php" method="post" id="page2" name="page2" enctype="multipart/form-data">
<table align="center" >
<tr>
<td>Enter the Value :</td>
<td><input type="text" name="value" id="value" /></td>
</tr>
<tr><td align="center"><input type="submit" name="submit" id="submit" value="submit" /></td>

</tr>
</table>
</form>
</body>

//page2.php
<?php
session_start();
$_SESSION['value'] = $_POST['value'];

//submit = $_POST['submit'];
//if(!empty($submit))
//{
//echo "value of textbox".$_SESSION['value'];
//}

?>
<body>
<h2>Use of Session</h2>
<form action="page3.php" method="post" id="page2" name="page2" enctype="multipart/form-data">
<table >
<tr>
<td>Enter the Value :</td>
<td><input type="text" name="value2" id="value2" /></td>
</tr>
<tr><td colspan="2">&nbsp;</td></tr>
<tr><td colspan="2">&nbsp;</td></tr>
<tr><td align="center"><input type="submit" name="submit" id="submit" value="submit" /></td>
</tr>
</table>
</form>
</body>

//page3.php

<?php
session_start();
$_SESSION['value2'] = $_POST['value2'];
$submit = $_POST['submit'];
//if(!empty($submit))
//{
//echo "value of First Page :"."<br/>".$value."<br/>"."<br/>";
//echo "value of Second Page :"."<br/>".$_SESSION['value2']."<br/>"."<br/>";
//echo "value of Third Page :"."<br/>".$_SESSION['value3'];
//}

?>
<body >
<h2 align="center" style="font-size:xx-large; color:#F06">Use of Session</h2>
<form action="last.php" method="post" id="page3" name="page3" enctype="multipart/form-data">
<br/>
<br/>
<br/>
<table>
<tr>
<td>Enter the Value :</td>
<td><input type="text" name="value3" id="value3" /></td>
</tr>
<tr><td align="center"><input type="submit" name="submit" id="submit" value="submit" /></td>

</tr>
</table>
</form>
</body>

//last.php

<?php
session_start();
$_SESSION['value3'] = $_POST['value3'];
$submit = $_POST['submit'];
?>

<body>
<h2>Use of Session</h2>
<form action="last.php" name="last" id="last" method="post">
<table align="center" >
<tr><td>Value1</td>
<td>Value2</td>
<td>Value3</td></tr>
<tr>
<?php if(!empty($submit))
{
?>
<td><?php echo $_SESSION['value']; ?></td>
<td><?php echo $_SESSION['value2']; ?></td>
<td><?php echo $_SESSION['value3']; ?></td>
<?php
}
?>
<tr><td colspan="2" align="center"><input type="submit" name="submit" value="submit" id="submit" /></tr>
</table>
</form>
</body>

Thanks,
i removed it from last.php like following

<?php
session_start();
/*$_SESSION = $_POST;

//$_SESSION = $_POST;
//$_SESSION = $_POST;
$submit = $_POST;
?>
but, it doesn't work.

Thanks, My last posing is wrong. The but 1 reply is correct and working.
Thank you very much Mr.liamfriel.

Thanks, My last posing is wrong. The but 1 reply is correct and working.
Thank you very much Mr.liamfriel.

No problem - we usually like to help those who have a go themselves and dont just ask us to do it for them - please give me positive rep for helping though :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.