I`ve read all similar questions I found. But most of the answers give solution to not trying to echo the values after submitting.
Here is my code:
<!DOCTYPE html>
<html>
<head>
<title>Post Request Example</title>
</head>
<body>
<form method="POST">
<label>Name: <input name="name"/></label><br/>
<label>Age: <input name="age"/></label><br/>
<label>Gender:</label><br/>
<label><input type="radio" name="gender" value="male">Male</label><br/>
<label><input type="radio" name="gender" value="female">Female</label><br/>
<input type="submit" name="submit" value="Submit" />
</form>
<?php
if (isset($_POST["name"]) && isset($_POST["age"]) && isset($_POST["gender"])) {
$name = $_POST["name"];
$age = $_POST["age"];
$gender = $_POST["gender"];
$result = "My name is " . $name . ". Im " . $age . " years old. Im " . $gender . ".";
echo $result;
}
?>
</body>
</html>
My question is: Why does this code work just fine when using $_GET on submitting and prints the result. And why it returns undefined when I use $_POST for submitting?
This is not the same question as Send value of submit button when form gets posted. There the situation is that the guy uses 2 submit buttons and can't receive their value. My problem is that I submit and the "echo" is not printed because my 3 values are empty. So I can't understand why my 3 variables are empty.
P.S.: I would use jQuery, but I'm on a PHP Course and we have that for homework.