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
Share on other sites

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;

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.