HTML Button, how to run php file with a parameter

Hi everyone,
My php code is consisted of 2 buttons as follows:

<!DOCTYPE HTML>
<html>
<body>
<button type="submit" onclick="myPHP.php/'1'">Click Me!</button>
<button type="submit" onclick="myPHP.php/'2'">Click Me!</button>
</body>
</html>

When user clicks left button I want the script to run “myPHP.php” with ‘1’ as a parameter, with
right button clicked I want “myPHP.php” to run with parameter ‘2’.
Is it possible to do?
Could anyone kindly explain me how?
Thanks

Yes, if you familiarise with the syntax of URLs:

The format for a (relative) url with a parameter is something like

myfile.php?param=1

which passes a parameter named param with a value of 1.

1 Like

Yes, using query strings is the easiest approach.

For gandalf’s example you can use $_GET['param'] to get the value.

1 Like

Thank you so much !

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.