Jump to content

[SOLVED] sessions and variables


jnerotrix

Recommended Posts

i have a website but and a form they input the data but i need the data they input into the form into a session so the variable is not forgotten

 

 

so lets say it was like this

 

<?php

<form action="2.php" method="post">
NAME: <input type="text" name="1"><br>
<input type="submit" value="go">
</form>

?>

 

NEXT PAGE

 

<?php 

session_start();

$name = $_POST['1'];

echo "hello $name";
?>
<a href="./3.php">GOTO THE NEXT PAGE</a>

 

 

3d PAGE

 

<?php 

session_start();

$name = $_POST['1'];

echo "hello $name";
?>

 

Bassicaly i need it to save the inputed data into a session thats rememberd over a series of pages

 

Link to comment
https://forums.phpfreaks.com/topic/142062-solved-sessions-and-variables/
Share on other sites

Your are correct to call session_start(); at the top of each page.  You just haven't added anything to the session array yet.  That is done like so.

 

<?php 

session_start();

$_SESSION['name'] = $_POST['1'];

echo "hello $_SESSION['name']";
?>
<a href="./3.php">GOTO THE NEXT PAGE</a>

 

 

<?php 

session_start();


echo "hello $_SESSION['name']";
?>

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.