Page 1 of 1

$_SESSION doesn't work???

Posted: Thu Jul 26, 2007 7:58 pm
by cturner
I have been testing $_SESSION and nothing displays on the second page. I have a textarea on the first page plus a rich text editor on the same page. The rich text editor is tiny_mce. I really need the textarea text to be added to a database however I haven't got to that yet. Can someone please tell me why this is happening and how I can solve the problem? Thanks in advance.

First page code:

Code: Select all

if (isset($_POST['savebtn'])) {
session_start();
$pageContent = $_POST['pageContent'];
$pageContent = $_SESSION['pageContent'];
header ('Location: test123.php');
Second page code:

Code: Select all

$pageContent = $_SESSION['pageContent'];
echo $pageContent;

Posted: Thu Jul 26, 2007 8:03 pm
by superdezign
You don't have session_start() at the beginning of the second page. Always make it the first statement of every page that uses the session.

Posted: Thu Jul 26, 2007 8:13 pm
by Zoxive
It might also help if you acually set a session variable.

Code: Select all

$_SESSION['pageContent'] = $pageContent;
When debugging use print_r alot : p

Code: Select all

print '<pre>'; print_r ($_SESSION); print '</pre>';
Then you can see if php is seeing what you want it to see.

Posted: Thu Jul 26, 2007 8:33 pm
by cturner
Thanks everyone, my code is working now.