ArizonaJohn Posted May 28, 2009 Share Posted May 28, 2009 Hello, I have the following HTML form at the top of a page called tsearch18.php. This page uses the variable "find" as a session variable. I would like the value of "find" to remain constant unless the user hits the submit button on the form below (or of course types a new value into the form and hits enter). So, I would like to trigger "unset($_SESSION['find']);" whenever the HTML form is used. But only then. How can I do this? I am having a hard time figuring out where to put "unset($_SESSION['find']);" I tried an if statement and it didn't work. Thanks in advance, John <div class="searchbox"> <form action="tsearch18.php" method="post"> <label>Enter Topic: <input type="text" name="find" size="55"/> <input type="hidden" name="searching" value="yes" /> <input type="submit" name="search" value="Search" /> </label> </form> </div> Quote Link to comment Share on other sites More sharing options...
paulman888888 Posted May 28, 2009 Share Posted May 28, 2009 add an if if(isset($_POST['submit'])){unset($_SOMeTHING)} Quote Link to comment Share on other sites More sharing options...
waynew Posted May 28, 2009 Share Posted May 28, 2009 if(isset($_POST['find'])){ if(isset($_SESSION['find'])){ unset($_SESSION['find']); } } Quote Link to comment Share on other sites More sharing options...
ArizonaJohn Posted May 28, 2009 Author Share Posted May 28, 2009 Hi Waynewex, That code does what I want... but I only want it to do that if the "Search" button is clicked. And then after the "Search" button is clicked, I want to re-set the session variable and keep it live. So far I can't get it to work. Quote Link to comment Share on other sites More sharing options...
waynew Posted May 28, 2009 Share Posted May 28, 2009 if(isset($_POST['search'])){ if(isset($_SESSION['find'])){ unset($_SESSION['find']); } $_SESSION['find'] = $_POST['find']; } Quote Link to comment Share on other sites More sharing options...
ArizonaJohn Posted May 28, 2009 Author Share Posted May 28, 2009 Hi Waynewex, Almost there... this is a little weird, but it works if the HTML form is used twice. So when I hit enter, the result is whatever had been entered into the search bar one attempt previously. Any ideas why it is doing that? Thanks Quote Link to comment Share on other sites More sharing options...
waynew Posted May 28, 2009 Share Posted May 28, 2009 So you're only wanting it to be set once, and no more thereafter? Quote Link to comment Share on other sites More sharing options...
ArizonaJohn Posted May 29, 2009 Author Share Posted May 29, 2009 No, I want the user to be able to reset without limit... every time something is entered into the HTML form. Quote Link to comment Share on other sites More sharing options...
fullyscintilla Posted May 29, 2009 Share Posted May 29, 2009 why do you need it stored in a session variable at all then..? Quote Link to comment Share on other sites More sharing options...
ArizonaJohn Posted May 29, 2009 Author Share Posted May 29, 2009 Later on, I use Ajax that refers to another page where I need the value of "find" to remain constant. Quote Link to comment Share on other sites More sharing options...
fullyscintilla Posted May 29, 2009 Share Posted May 29, 2009 you could always create a secondary session variable to temp hold on to values and then reset that value each time a new value is submitted Quote Link to comment Share on other sites More sharing options...
ArizonaJohn Posted May 29, 2009 Author Share Posted May 29, 2009 How would I do that? Quote Link to comment Share on other sites More sharing options...
fullyscintilla Posted May 29, 2009 Share Posted May 29, 2009 if(isset($_POST['search']) { $Find = $_POST['find']; $_SESSION['find'] = $_POST['find']; } ? Hard to tell without knowing the rest of your code 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.