Jump to content

Quick Session Question


amg182

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/243991-quick-session-question/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.