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. Link to comment https://forums.phpfreaks.com/topic/59382-solved-how-do-you-do-this/ 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 Link to comment https://forums.phpfreaks.com/topic/59382-solved-how-do-you-do-this/#findComment-295003 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. Link to comment https://forums.phpfreaks.com/topic/59382-solved-how-do-you-do-this/#findComment-295006 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']; ?> Link to comment https://forums.phpfreaks.com/topic/59382-solved-how-do-you-do-this/#findComment-295009 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. Link to comment https://forums.phpfreaks.com/topic/59382-solved-how-do-you-do-this/#findComment-295013 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]'":'')."/>"; Link to comment https://forums.phpfreaks.com/topic/59382-solved-how-do-you-do-this/#findComment-295132 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.