Helping ordinary people create extraordinary websites!

Go Back   Web Development Forum > Website Programming > Server-Side Scripting
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-03-2008, 12:31 AM
ryanhellyer's Avatar
Super Moderator
 
Join Date: Dec 2007
Posts: 632
Default Issues with PHP sessions

I read the other topic on here recently about PHP sessions. So I decided to have a crack at setting them up myself for a small project I'm working on. However I'm having trouble with my code

The following code does exactly what I want it to, but I need to click submit twice for the effects to be shown.

PHP Code:
<?php session_start(); ?>

<form method="post" action="example2.php">
    <input type="text" name="bla" value="<?php echo $bla?>" />
    <input type="hidden" name="action" value="update" />
    <input type="submit" name="Submit" /></p>
</form>

<h1><?php echo $bla?></h1>

<?php
    
foreach ($_POST as $key=>$value)
    {
$_SESSION[$key] = $value;}
?>
Do any of you know what I'm doing wrong?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-03-2008, 12:49 AM
Member
 
Join Date: Jan 2008
Posts: 37
Default

Your session data doesnt exist untill after the form is done.

Move the following code to the top of your page, just below session_start().
PHP Code:
<?php
    
foreach ($_POST as $key=>$value)
    {
$_SESSION[$key] = $value;}
?>
__________________
gribbit
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-03-2008, 03:01 AM
ryanhellyer's Avatar
Super Moderator
 
Join Date: Dec 2007
Posts: 632
Default

Thanks

That did the trick!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 09:18 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.