ballhogjoni Posted July 11, 2007 Share Posted July 11, 2007 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. Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 11, 2007 Share Posted July 11, 2007 when you refresh the page it still get the value whats the prob try to refresh this page and you will still see the posted input Quote Link to comment Share on other sites More sharing options...
ballhogjoni Posted July 11, 2007 Author Share Posted July 11, 2007 thats why i am writing this because that doesn't work in this case. I am posting variable from a form on one page and then receiveing it on another. Quote Link to comment Share on other sites More sharing options...
trq Posted July 11, 2007 Share Posted July 11, 2007 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']; ?> Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted July 11, 2007 Share Posted July 11, 2007 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. Quote Link to comment Share on other sites More sharing options...
Azu Posted July 11, 2007 Share Posted July 11, 2007 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]'":'')."/>"; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.