nikee
09-04-2009, 12:28 PM
Hey.
I'm a beginner to PHP and i'm currently trying to learn about sessions.
What i'm trying to do is to submit data from one page, save it in as a session variable and then navigate to another page and echo the session variable. But i believe i'm missing something, because it's just not working.
I get this error:
Parse error: parse error in C:\wamp\www\index2.php on line 3
I have two files. index.php and index2.php
index.php:
<?php
session_start();
$_SESSION['name']='';
if (isset($_POST['submit'])) {
$_SESSION['name'] = $_POST['name'];
echo 'The value of $_SESSION["name"] is now set to "' . $_SESSION['name'] . '"<br />';
echo '<a href="index2.php">Next Page</a>';
} else {
echo '
<form action="index.php" method="POST">
<input type="text" name="name" value="Nicklas Sandell">
<input type="submit" name="submit" value="Submit">
</form>
';
}
?>
index2.php
<?php
session_start()
echo 'The value of name is '.$_SESSION['name'];
?>
The error message says that the error is in index2.php and on line 3, and this is the code i have on that line:
echo 'The value of name is '.$_SESSION['name'];
So... can someone tell me what's going on here? I've been trying to find the error for so long now. It's so annoying!
Thanks.
-Nike
I'm a beginner to PHP and i'm currently trying to learn about sessions.
What i'm trying to do is to submit data from one page, save it in as a session variable and then navigate to another page and echo the session variable. But i believe i'm missing something, because it's just not working.
I get this error:
Parse error: parse error in C:\wamp\www\index2.php on line 3
I have two files. index.php and index2.php
index.php:
<?php
session_start();
$_SESSION['name']='';
if (isset($_POST['submit'])) {
$_SESSION['name'] = $_POST['name'];
echo 'The value of $_SESSION["name"] is now set to "' . $_SESSION['name'] . '"<br />';
echo '<a href="index2.php">Next Page</a>';
} else {
echo '
<form action="index.php" method="POST">
<input type="text" name="name" value="Nicklas Sandell">
<input type="submit" name="submit" value="Submit">
</form>
';
}
?>
index2.php
<?php
session_start()
echo 'The value of name is '.$_SESSION['name'];
?>
The error message says that the error is in index2.php and on line 3, and this is the code i have on that line:
echo 'The value of name is '.$_SESSION['name'];
So... can someone tell me what's going on here? I've been trying to find the error for so long now. It's so annoying!
Thanks.
-Nike