Hi,
As I mentioned in my intro, I've just started learning PHP. I'm trying to write a script which will have three visible pages - one is asking for the user's name, and which page they would like to visit. The other two will be the pages which they can select from the first page, and a message saying hello.
I've got this working through the session tag, but only when the form code is set to go a particular page. To allow the user to select, I've added a non-visible page, called redirect.php, which takes the value selected in the first page (the drop-down, for which page they'd like to visit), and sends them to that page. When I go through the redirect page, the session doesn't appear to 'keep' the user's name, entered on the first page.
The redirect script seems to work okay, but the variable containing the username seems to be blank in the final script.
Can someone advise where I'm going wrong? The three scripts are below:
Starting Page:
<?php
session_start();
$_SESSION[‘uname’] = “testing”;
?>
<html>
<head>
</head>
<body>
<?php
echo "<form action='redirect.php' method='post'>
<p><input type='text' name='uname'><br>
<select name='gourl'>
<option value=''>Choose a Destination...
<option value='test2.php'>Test Page 2
<option value='test3.php'>Test Page 3
</select>
<input type='submit' value='Go'>
</form>";
?>
</body></html>
Redirect Script:
<?php
$url = $_POST["gourl"];
header("Location: $url");
?>
Final Page:
<html><body>
<?php
$testinghere = $_SESSION['uname'];
echo "Hello, $testinghere \n";
?>
</body></html>
I've tried loads of small edits, but like I said, I'm a beginner, so any expert advice would be very much appreciated!