Jump to content

[SOLVED] how do you do this?


ballhogjoni

Recommended Posts

How do you lock a variable so that when you refresh a page it doesn't disapear?

 

example:

$variable = $_POST['variable'];

 

then I refresh the page but I want the $variable to still hold its value. I tried:

 

$_SESSION['variable'] = $_POST['variable'];

 

but that din't work.

Link to comment
Share on other sites

How do you lock a variable so that when you refresh a page it doesn't disapear?

 

You don't under normal circumstance. HTTP has no state.

 

<?php

 session_start();
 if (!isset($_SESSION['started'])) {
   $_SESSION['started'] = $_POST['variable'];
 }

 echo $_SESSION['started'];

?>

Link to comment
Share on other sites

Ok try it like this:

session_start();
$variable = $_POST['variable'];

$_SESSION['variable'] = $variable;

Now ur input type text:

 

<input type='text' name='text2' value=<?php echo $_SESSION['variable']?>>

 

Hope this will help.

Link to comment
Share on other sites

How do you lock a variable so that when you refresh a page it doesn't disapear?

 

example:

$variable = $_POST['variable'];

 

then I refresh the page but I want the $variable to still hold its value. I tried:

 

$_SESSION['variable'] = $_POST['variable'];

 

but that din't work.

 

Try this;

 

session_start();

$_SESSION['variable']=($_SESSION['variable']&&!$_POST['whatever'])?$_SESSION['variable']:$_POST['whatever'];

echo"<input type='text' name='whatever'".(($_SESSION['variable'])?" value='$_SESSION[variable]'":'')."/>";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.