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
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.
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:
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!