Viswalinga Surya S Viswalinga Surya S - 7 months ago 16
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>`
.
.
.

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


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

Answer

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

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

Then in your display.php file :

<?php
    if(isset($_GET["data"]) && isset($_GET["data2"]))
    {
        $data = $_GET["data"];
        $data2 = $_GET["data2"];
    }
?>

Here you go.