p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: Post variables and custom session functions conflict?


Message #1 by "John Arbon" <subscriptions@c...> on Thu, 30 May 2002 03:00:30
I am using custom session functions to handle the session's registered 
variables.  However, when I try to change the values through a form that 
calls itself I get the old, unwanted values back.

Let me give you an example of what I am talking about:

<?

  include_once("custom_session.inc");
  session_start();

  $body = "<html>
             <head><title></title</head>
             <body>
               <form method='post' action='$PHP_SELF'>
                 <input type='text' name=var1 value='$var1'>
                 <input type='submit' name='submit' value='Test'>
               </form>
             </body>
           </html>
           ";

  echo $body;

?>


The variable "var1" is a session_registered variable.  (In the database 
where it is stored it shows the value of the variable to be "Old Value".)  
When I click on the submit button, the form is supposed to call itself and 
update the text field with the changed information.

If my old value for $var1 was "Old Value", and I was looking at the form 
and changed that field to "New Value" then pressed the submit button, I 
would expect that the text field, upon display, to show "New Value", but 
it does not.  I still see "Old Value".

I'm not sure why the value is not being updated.

Any help?  I could post the entire code, but it is quite long, but if you 
require it, I will.

John
Message #2 by "John Arbon" <subscriptions@c...> on Thu, 30 May 2002 03:06:44
Wait a minute...

The thought just occured to me, that the session function is calling the 
value of the variables from the database BEFORE these variables can be re-
assigned the newly submitted values, therefore the connection between new 
values and variables is never made...

If this is true, would a better way around this would be to assign non-
register variables the values of the registered variables and manipulate 
those first, then on acceptance of the new values by the user, reassign 
the registered varables the new values using the "registeredVariable = 
acceptedValueVariable" syntax?

John













> I am using custom session functions to handle the session's registered 
v> ariables.  However, when I try to change the values through a form that 
c> alls itself I get the old, unwanted values back.

> Let me give you an example of what I am talking about:

> <?

>   include_once("custom_session.inc");
 >  session_start();

>   $body = "<html>
 >             <head><title></title</head>
 >             <body>
 >               <form method='post' action='$PHP_SELF'>
 >                 <input type='text' name=var1 value='$var1'>
 >                 <input type='submit' name='submit' value='Test'>
 >               </form>
 >             </body>
 >           </html>
 >           ";

>   echo $body;

> ?>

> 
T> he variable "var1" is a session_registered variable.  (In the database 
w> here it is stored it shows the value of the variable to be "Old 
Value".)  
W> hen I click on the submit button, the form is supposed to call itself 
and 
u> pdate the text field with the changed information.

> If my old value for $var1 was "Old Value", and I was looking at the form 
a> nd changed that field to "New Value" then pressed the submit button, I 
w> ould expect that the text field, upon display, to show "New Value", but 
i> t does not.  I still see "Old Value".

> I'm not sure why the value is not being updated.

> Any help?  I could post the entire code, but it is quite long, but if 
you 
r> equire it, I will.

> John

  Return to Index