Passing a php varible in a html list

Discussion in 'PHP' started by joewills, Feb 11, 2006.

  1. #1
    Hi,

    I would like to pass a variable from one php page to another (search.php) according to what is selected in the list

    if a is selected, then pass a as variable. Here is the HTML for the list

    <div id="azindex">
    <ul id="index">
    <li><a href="/search.php">A</a></li>
    <li><a href="/search.php">B</a></li>
    <li><a href="/search.php">C</a></li>
    <li><a href="/search.php">D</a></li>
    <li><a href="/search.php">E</a></li>
    <li><a href="/search.php">F</a></li>
    <li><a href="/search.php">G</a></li>
    </ul>
    </div>
    </div>


    Many thanks,

    Joe
     
    joewills, Feb 11, 2006 IP
  2. eKstreme

    eKstreme Guest

    Messages:
    131
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi

    How about something like this:
    
    <div id="azindex">
    <ul id="index">
    <li><a href="/search.php?variable=A">A</a></li>
    <li><a href="/search.php?variable=B">B</a></li>
    ...
    </ul>
    </div>
    </div>
    
    Code (markup):
    Then in search.php, check the value of $_GET['A']. If none is specified or a bogus one is given, default to a value or throw an error.
     
    eKstreme, Feb 11, 2006 IP
  3. yo-yo

    yo-yo Well-Known Member

    Messages:
    4,619
    Likes Received:
    206
    Best Answers:
    0
    Trophy Points:
    185
    #3
    The HTML for your page:
    <div id="azindex">      
    <ul id="index">
    <li><a href="/search.php?q=A">A</a></li>
    <li><a href="/search.php?q=B">B</a></li>
    <li><a href="/search.php?q=C">C</a></li>
    <li><a href="/search.php?q=D">D</a></li>
    <li><a href="/search.php?q=E">E</a></li>
    <li><a href="/search.php?q=F">F</a></li>
    <li><a href="/search.php?q=G">G</a></li>
    </ul>
    </div>
    HTML:
    The code for search.php
    <?php
    $your_variable = $_GET['q'];
    ?>
    PHP:
     
    yo-yo, Feb 11, 2006 IP
  4. joewills

    joewills Peon

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Cheers guys!!
     
    joewills, Feb 11, 2006 IP
  5. yo-yo

    yo-yo Well-Known Member

    Messages:
    4,619
    Likes Received:
    206
    Best Answers:
    0
    Trophy Points:
    185
    #5
    Any Time :)
     
    yo-yo, Feb 11, 2006 IP
  6. eKstreme

    eKstreme Guest

    Messages:
    131
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You're welcome :)

    One tip though: make sure you "sanitize" $your_variable when you pick it up. If you're using it to query databases, make sure you escape any nasty strings. If you're going to embed it into a web page, make sure it doesn't have any HTML tags. That is, don't trust it and secure it!
     
    eKstreme, Feb 15, 2006 IP