1<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
2 Name: <input type="text" name="fname">
3 <input type="submit">
4</form>
5<?php
6if ($_SERVER["REQUEST_METHOD"] == "POST") {
7 // do logic
8 $name = $_POST['fname'];
9}
10?>
1// Send data trough e.g. AJAX in JavaScript
2
3$.ajax({
4 type: "POST",
5 url: 'example.php',
6 data: { "num1": 1, "num2": 2},
7 contentType: "application/json; charset=utf-8",
8 dataType: "JSON",
9 async: false
10})
11
12// You would receive it like this:
13
14$num1 = $_POST["num1"];
15$num2 = $_POST["num2"];
16
17$sum = $num1 + $num2;
18echo $sum;
19
20// Would output: 3