Viswalinga Surya S Viswalinga Surya S - 2 years ago 100
PHP Question

How to send a data to PHP page when clicking on a Link?

I have several links in an HTML page (say some 100 - 120). What I exactly need is to send different data to another PHP page (say display.php) when I click on each link. I tried a pathetic method,

<form action="display.php" method="post"> // or GET
<input type="hidden" name ="data" value="Data1" />
<input type="submit" value="Link 1" />

<form action="display.php" method="post">
<input type="hidden" name ="data" value="Data120" />
<input type="submit" value="Link 120" />

Is there any simple way to reduce the usage of these 120 forms?

Answer Source

You can put data directly on the href of your tag.

<a href="./display.php?data=Data1&data2=Data120">Click here</a>

Then in your display.php file :

    if(isset($_GET["data"]) && isset($_GET["data2"]))
        $data = $_GET["data"];
        $data2 = $_GET["data2"];

Here you go.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download