1<!DOCTYPE html>
2<html>
3
4<head>
5 <title>
6 How to call PHP function
7 on the click of a Button ?
8 </title>
9</head>
10
11<body style="text-align:center;">
12
13 <h1 style="color:green;">
14 GeeksforGeeks
15 </h1>
16
17 <h4>
18 How to call PHP function
19 on the click of a Button ?
20 </h4>
21
22 <?php
23
24 if(isset($_POST['button1'])) {
25 echo "This is Button1 that is selected";
26 }
27 if(isset($_POST['button2'])) {
28 echo "This is Button2 that is selected";
29 }
30 ?>
31
32 <form method="post">
33 <input type="submit" name="button1"
34 value="Button1"/>
35
36 <input type="submit" name="button2"
37 value="Button2"/>
38 </form>
39</head>
40
41</html>
42
1<!DOCTYPE HTML>
2<html>
3<?php
4 function runMyFunction() {
5 echo 'I just ran a php function';
6 }
7
8 if (isset($_GET['hello'])) {
9 runMyFunction();
10 }
11?>
12
13Hello there!
14<a href='index.php?hello=true'>Run PHP Function</a>
15</html>
16