I have these pages that asks user for values. when I try to use the links to previous pages, the session values are gone and it requires user to go back to the first and repeat the process.
Here are sample codes based of my original code:
page1.php
<?php
session_start();
echo "<form method='POST' action='page2.php'>";
echo "<input type='text' name='date1'>";
echo "<input type='text' name='date2'>";
echo "<input type='submit'>"
echo "</form>";
?>
page2.php
<?php
session_start();
$_SESSION['date1'] = $_POST['date1'];
$_SESSION['date2'] = $_POST['date2'];
echo "<form method='POST' action='page3.php'>";
echo "<input type='text' name='info1'>";
echo "<input type='text' name='info2'>";
echo "<input type='submit'>"
echo "</form>";
echo "<a href='page1.php'>Change value in page 1</a>";
?>
page3.php
<?php
session_start();
$_SESSION['info1'] = $_POST['info1'];
$_SESSION['info2'] = $_POST['info2'];
if(isset($_POST['confirm'])){
$mysql_host = 'localhost';
$mysql_user = 'root';
$mysql_pass = '';
$db = 'sampDB';
$conn = mysqli_connect($mysql_host, $mysql_user, $mysql_pass, $db);
$query = mysqli_query($conn, 'INSERT INTO info(date1, date2, info1, info2)
VALUE ('$_SESSION[date1]', '$_SESSION[date2]', '$_SESSION[info1]', '$_SESSION[info2]')');
}
echo "<form method='POST'>";
echo $_SESSION['date1'];
echo $_SESSION['date2'];
echo $_SESSION['info1'];
echo $_SESSION['info2'];
echo "<input type='submit' name='confirm'>"
echo "</form>";
echo "<a href='page1.php'>Change value in page 1</a>";
echo "<a href='page2.php'>Change value in page 2</a>";
?>
How do I go back to previos pages without destroying the values from the session?