$_SESSION doesn't work???

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
cturner
Forum Contributor
Posts: 153
Joined: Sun Jul 16, 2006 3:03 am
Location: My computer

$_SESSION doesn't work???

Post 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;
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post 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.
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post 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.
Last edited by Zoxive on Thu Jul 26, 2007 8:40 pm, edited 1 time in total.
User avatar
cturner
Forum Contributor
Posts: 153
Joined: Sun Jul 16, 2006 3:03 am
Location: My computer

Post by cturner »

Thanks everyone, my code is working now.
Post Reply