amg182 Posted August 6, 2011 Share Posted August 6, 2011 Hi guys. I have an input form that a user can filter the query of mysql results, works fine but i would like the variable to be remembered when the user navigates away from the page and returns to it. I thought i set up the $_sessions properly but, obivously i am not doing it correctly.... :-\ Here is what i am working with: <?php session_start(); if (!isset($_POST['model'])) $_POST['model'] = ""; if (!isset($model) && isset($_SESSION["model"])) $model = $_SESSION["model"]; ?> <form name="Model Filter" action="" method="post"> Model: <Select name="model"> <option "Input" value="<?php echo $_POST['model']; ?>"><?php echo $_POST['model']; ?></option> <option value="">All</option> <option value="Escort">Escort</option> <option value="Focus">Focus</option> </select> <input type="submit" value="Add Filter" /> </form> <?php $model=""; if($_POST['model']=="") { } else { $model=" AND model='".$_POST['model']."'"; } $result="SELECT * FROM cars WHERE Make='Ford'".$model; $result=mysql_query($result); while($row = mysql_fetch_array($result)) { echo $row['Make']; echo $row['Model']; echo "<br>"; } ?> Thanks Quote Link to comment https://forums.phpfreaks.com/topic/243991-quick-session-question/ Share on other sites More sharing options...
trq Posted August 6, 2011 Share Posted August 6, 2011 You never put anything in the $_SESSION array. Quote Link to comment https://forums.phpfreaks.com/topic/243991-quick-session-question/#findComment-1252934 Share on other sites More sharing options...
amg182 Posted August 6, 2011 Author Share Posted August 6, 2011 Sorry, do you mean I have not put anything into the array or there should not be anything in the array? Sorry for being ignorant, i am very new to php... Thanks Quote Link to comment https://forums.phpfreaks.com/topic/243991-quick-session-question/#findComment-1252955 Share on other sites More sharing options...
gizmola Posted August 6, 2011 Share Posted August 6, 2011 He means that you never assign any variables to $_SESSION in your code. At the top add this 2nd line below yours: if (!isset($model) && isset($_SESSION["model"])) $model = $_SESSION["model"]; $_SESSION['model'] = $model; Quote Link to comment https://forums.phpfreaks.com/topic/243991-quick-session-question/#findComment-1252958 Share on other sites More sharing options...
amg182 Posted August 6, 2011 Author Share Posted August 6, 2011 Tried that, but still no luck? Quote Link to comment https://forums.phpfreaks.com/topic/243991-quick-session-question/#findComment-1253155 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.