The form processing code needs to replace the remaining original echo line (in the else part of the if/else):
$firstvalue=$_POST["firstname"];
$secondvalue=$_POST["surname"];
$thirdvalue=$_POST["dob"];
echo "Hello $firstvalue $secondvalue if I knew maths I could calculate your age now.";
Refresh the page (let the browser reload/resubmit the data). This time you should see the text you put into the form.
Proper HTML
Look at the source code for the page in your browser. It is not a proper HTML page as you have only output some text and not used the basic HTML elements. This is because those are only there for the if part. To make the HTML correct in both parts of the page take the basic tags out of the if and put them before and after. Delete everything in formandprocess.php and replace it with this:
<?php
error_reporting(E_ALL);
ini_set("display_errors", TRUE);
?>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<?php
if (!$_POST) {
?>
<h1>A form</h1>
<form method="post" action="formandprocess.php">
<p><label for="firstname">Type your first name here: </label><input type="text" name="firstname" id="firstname"></p>
<p><label for="surname">Type your surname here: </label><input type="text" name="surname" id="surname"></p>
<p><label for="dob">Your date of birth (dd/mm/yyyy): </label><input type="text" name="dob" id="dob"></p>
<p><input type="submit" name="submit"></p>
</form>
</body>
</html>
<?php
} else {
$firstvalue=$_POST["firstname"];
$secondvalue=$_POST["surname"];
$thirdvalue=$_POST["dob"];
echo "<h1>A reply</h1>";
echo "<p>Hello $firstvalue $secondvalue if I knew maths I could calculate your age now.</p>";
}
?>
</body>
</html>
Look through that code and make sure you understand it. Starting and stopping PHP mode like that can get confusing and may be the most annoying part of PHP but what is happening is fairly simple:
- do some PHP first then turn off PHP mode
- output the basic HTML needed at the top of any Web page
- do the PHP if statement and form display or processing which results in different stuff inside the HTML body element
- do the basic HTML needed at the bottom of every Web page