Jump to content

using Sessions to search


harkly

Recommended Posts

I have a search page on my site and I want to be able to have the info searched on be put in SESSIONs and then use that info to "search" with whenever a particular link is selected (Back to Search)

 

I have the searched info in the SESSIONs

 

$gender=$_POST["gender"];

$_SESSION['gender']=$gender;

so far it seems to work, pulling up the correct info on every page

 

 

 

How do I go about getting this link to use that info to repopulate the search page?

 

<a href='search.php' title='Back to Search'>Back to Search</a>

 

 

In a nutshell what I want is to...

 

do a search on index.php

that info will display on searched.php

you can then go to any other page but when you click on <a href='search.php' title='Back to Search'>Back to Search</a>

it will take you back to searched.php with the same original data displayed

Link to comment
https://forums.phpfreaks.com/topic/214852-using-sessions-to-search/
Share on other sites

hmm, not so sure about that.

 

I have gotten a test page to work but now am wondering if there is a way to combine the 2 if's into one, so I don't have to repeat the code. This is a test page the really one is very large.

 

form from index.php goes to here (search.php)

  if( isset($_POST['search'])){

 

link will take back to search.php

  else if(isset($_GET['action']) && strcasecmp($_GET['action'], "search") == 0)

 

full code of 2nd page

<?php

  session_start();

  if( isset($_POST['search'])){

    $name=$_POST["name"];
    $password=$_POST["password"];

    $_SESSION['name'] = $name;
    $_SESSION['password'] = $password;

    echo "User : ".$_SESSION['name'];
    echo "Password : ".$_SESSION['password'];

    echo "<br><br><a href='sessionPage1.php'>Page 1</a> ";

    echo "<br><a href='sessionPage3.php'>Page 3</a> ";

    echo "<br><a href='sessionPage4.php'>Page 4</a> ";
  }

  else if(isset($_GET['action']) && strcasecmp($_GET['action'], "search") == 0)
  {

    echo "User : ".$_SESSION['name'];
    echo "Password : ".$_SESSION['password'];

    echo "<br><br><a href='sessionPage1.php'>Page 1</a> ";

    echo "<br><a href='sessionPage3.php'>Page 3</a> ";

    echo "<br><a href='sessionPage4.php'>Page 4</a> ";
  }
  else 
  {
    echo "<br>Not valid "; 
    echo "<br><br><a href='sessionPage1.php'>Page 1</a> ";}

?>




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.