I am currently working with three pages of code, 1 HTML and 2 PHP. When a user submits their first name, last name and age it should display on the first PHP page and outputs a string thanking them for entering their info then simultaneously the HTML form data should be 1)Appended to a text file on my hard drive and 2)Outputted to an HTML table on the browser in a 3rd PHP page. I am having trouble with outputting the user data to the 3rd PHP page. I also do not receive any errors in my code which makes it difficult to pinpoint the issue. Why is my code not appending the data to the HTML table in the third PHP page?
HTML
<form action="page2.php" method="post" name="form">
<p>Enter your info</p>
<p>First Name:<br>
<input type="text" name="firstname" id="firstname">
</p>
<p>Last Name:<br>
<input type="text" name="lastname" id="lastname">
</p>
<p>Age:<br>
<input type="text" name="age" id="age" size="3">
</p>
PHP PAGE 2
if(isset($_POST['submit'])){
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$age= $_POST['age'];}
$filename ='files/addusers.txt';
$fp = fopen($filename, 'a');
$text = $firstname. '|' . $lastname. '|' . $age. '|' . "\n";
fwrite($fp, $text);
fclose($fp);
PHP/HTML Page 3
if(isset($_POST['submit'])){
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$age= $_POST['age'];
$filename ='files/addusers.txt';
?>
<table border = '1'>
<tr>
<th>Last Name</th>
<th>First Name</th>
<th>Age</th>
</tr>
<?php
/*Insert User Info to HTML table*/
$output_results = "";
$cntr = 0;
$fp = fopen($filename, 'r');
while(true){
$line = fgets($fp);
if (feof($fp))
{
break;
}
$cntr++;
list($lastname, $firstname, $email, $bYear, $city) = explode('|', $line);
$output_results .= "<tr>";
$output_results .= "<td>".$lastname."</td>";
$output_results .= "<td>".$firstname."</td>";
$output_results .= "<td>". $age."</td>";
$output_results .= "</tr>\n";
}
fclose($fp);
print $output_results;
}//END OF ISSET
?>
</table>