开发者

How to pick an html 'a' <a> tag using php, especially by POST or GET technique?

Suppose I have a code like this in my page

<a href="some_url" name="" value=""> Jokes</a>
<a href="some_url" name="" value=""> Quotes</a>

Now If I click on one of these links, say I clicked the 'Jokes' link, I want to pick up the 'Jokes' category through POST or GET method of php and compare it my categories in MYSQL database. If there is a match, then I want to display certain details.

Please开发者_运维问答 help me on how to proceed with this.


You will need to construct the some_url to have parameters on it that relate to the Joke category. For example

<a href="http://www.example.com/show.php?category=jokes">Jokes</a>

<a href="http://www.example.com/show.php?category=quotes">Quotes</a>

Then in your script (let's say show.php you would query the $_GET['category'] parameter and use that to compare against your database records.

Make sure you sanitize all GET and POST parameters prior to them being used in a database query (or for any other purpose really). You can not trust that input from the user will be friendly. Refer to this link for information about escaping dangerous characters, or better yet, use PDO with prepared statements

I'm not sure if name and value are valid attributes of an <a> tag.


<?php

$category = $_GET['category'];

?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜