Search form + html link search term to same search page.

Discussion in 'PHP' started by philb, Nov 16, 2011.

  1. #1
    I have an 'index.php' page which uses a form to pass a search term to the 'searchresults.php' page.

    I use the POST and GET as usual.

    $term=$_POST['term'];
    PHP:
    All works fine.


    I'd like to include some text keywords on the 'index.php' page which can also be passed to the 'searchresults.php'

    I can use an html link like

    <a href="../shop/cat/searchresults.php?term=leather">leather</a>

    with the

    $term=$_GET['term'];
    PHP:
    But i'm having trouble using both at the same time.

    Can anyone help me find a solution?
     
    philb, Nov 16, 2011 IP
  2. philb

    philb Peon

    Messages:
    61
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I've found a fix by using REQUEST instead of both POST and GET

    Brilliant
     
    philb, Nov 16, 2011 IP
  3. suryawl

    suryawl Peon

    Messages:
    54
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #3
    if you still haven't found the solution

    if ($_POST['term']) $term = $_POST['term'];
    else $term = $_GET['term'];

    Hope that helps
     
    suryawl, Nov 16, 2011 IP
  4. philb

    philb Peon

    Messages:
    61
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks Suryawl

    It seems $_REQUEST is doing the job

    REQUEST: An associative array that by default contains the contents of $_GET, $_POST and $_COOKIE.
     
    philb, Nov 16, 2011 IP