CodeMama Posted August 12, 2009 Share Posted August 12, 2009 I found a couple examples and have tried and they all seem to be based around this but it doesn't work anyone see my error? <tr> <td width="20%" align="right" height="30"><div class="admin_Caption">Name:</div></td> <td width="80%" height="30"><input name="searchname" type="text" size="30" <?php if(isset($_SESSION['searchname'])) { echo " value='" . $_SESSION['searchname'] . " ['searchname'] '"; } ?> > </td> </tr> The session_start() is at the top of my page along with checking for the sessions.... help help Quote Link to comment https://forums.phpfreaks.com/topic/169970-solved-help-with-keeping-form-fields-populated-using-sessions/ Share on other sites More sharing options...
wildteen88 Posted August 12, 2009 Share Posted August 12, 2009 That code looks ok. What is it doing now? Is the form field populated? If its not can you post how the $_SESSION['searchname'] variable is being defined? Quote Link to comment https://forums.phpfreaks.com/topic/169970-solved-help-with-keeping-form-fields-populated-using-sessions/#findComment-896641 Share on other sites More sharing options...
smerny Posted August 12, 2009 Share Posted August 12, 2009 You're wanting it to... like for example if searchname is "CodeMama" you want it to say this? value='CodeMama ['searchname'] ' because thats what you have set... and actually that will create a problem because you have single quotes within single quotes. I would assume you just want value='CodeMama'... which means you just do this: echo " value='" . $_SESSION['searchname'] ."'"; Quote Link to comment https://forums.phpfreaks.com/topic/169970-solved-help-with-keeping-form-fields-populated-using-sessions/#findComment-896643 Share on other sites More sharing options...
CodeMama Posted August 12, 2009 Author Share Posted August 12, 2009 Thanks going to change it to smerny suggestion see if on submit it holds the values ...I may be back Quote Link to comment https://forums.phpfreaks.com/topic/169970-solved-help-with-keeping-form-fields-populated-using-sessions/#findComment-896649 Share on other sites More sharing options...
CodeMama Posted August 12, 2009 Author Share Posted August 12, 2009 well I added it and now when I reload the page it wouldn't release the sessions, so I put this // Check if there was an empty search sent if(isset($_SESSION['noVarsSent'])) { echo "<p><b>No values were submitted for the search.</b></p>"; // Unset it so a reload of page doesn't redisplay the error unset($_SESSION['noVarsSent']); unset($_SESSION['results']); unset($_SESSION['searchname']); unset($_SESSION['address']); unset($_SESSION['bmonth']); unset($_SESSION['bday']); unset($_SESSION['byear']); unset($_SESSION['emonth']); unset($_SESSION['eday']); unset($_SESSION['eyear']); unset($_SESSION['totalNumberOfRestaurants']); }else{ $_SESSION['searchname'] = $_POST; $_SESSION['address'] = $_POST; $_SESSION['bmonth'] = $_POST; $_SESSION['bday'] = $_POST; $_SESSION['byear'] = $_POST; $_SESSION['emonth'] = $_POST; $_SESSION['eday'] = $_POST; $_SESSION['eyear'] = $_POST; } ?> now when I reload the page it says "Array" in the search text boxes? Quote Link to comment https://forums.phpfreaks.com/topic/169970-solved-help-with-keeping-form-fields-populated-using-sessions/#findComment-896670 Share on other sites More sharing options...
smerny Posted August 12, 2009 Share Posted August 12, 2009 $_SESSION['searchname'] = $_POST; unless it's something about php that i don't know about, that wont do anything...try $_SESSION['searchname'] = $_POST['searchname']; ======== also not sure how this is getting set? if(isset($_SESSION['noVarsSent'])) I'm also unsure of what the bigger picture looks like in this situation so maybe thats why I'm confused Quote Link to comment https://forums.phpfreaks.com/topic/169970-solved-help-with-keeping-form-fields-populated-using-sessions/#findComment-896672 Share on other sites More sharing options...
CodeMama Posted August 12, 2009 Author Share Posted August 12, 2009 wow this is getting tricky...I put the $_POST =['blah'] in there and it just gave me a bunch of undefined variable errors, so I put it like this which got rid of the errors but...doesn't keep the values <tr> <td width="20%" align="right" height="30"><div class="admin_Caption">Name:</div></td> <td width="80%" height="30"><input name="searchname" type="text" size="30" <?php if(isset($_SESSION['searchname'])) { echo " value='" . $_SESSION['searchname'] = $_POST['searchname'] ."'"; } ?> > </td> </tr> Quote Link to comment https://forums.phpfreaks.com/topic/169970-solved-help-with-keeping-form-fields-populated-using-sessions/#findComment-896697 Share on other sites More sharing options...
smerny Posted August 12, 2009 Share Posted August 12, 2009 your code is saying... if $_SESSION['searchname'] is already set, set it... otherwise leave it unset ? does your form action load this page that you are taking the code from? if so you could just switch if(isset($_SESSION['searchname'])) with if(isset($_POST['searchname'])) Quote Link to comment https://forums.phpfreaks.com/topic/169970-solved-help-with-keeping-form-fields-populated-using-sessions/#findComment-896703 Share on other sites More sharing options...
darkfreaks Posted August 12, 2009 Share Posted August 12, 2009 Try this: <?php if(isset($_POST['blah'])){ $_SESSION['blah']= $_POST['blah']; echo $_SESSION['blah']; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/169970-solved-help-with-keeping-form-fields-populated-using-sessions/#findComment-896728 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.