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["submit"])) {
$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?
P.S.: I would use jQuery, but I'm on a PHP Course and we have that for homework.
Aucun commentaire:
Enregistrer un commentaire