This is my code:
<?php
extract ($_POST);
$fh = fopen ("./s.txt", "a");
echo file_get_contents( "./s.txt" );
if(($line = fgets($fh)) !== false) {}
echo($line);
file_put_contents("./signup.txt", "");
if($line!=false && $line!='') {
echo '<script language="javascript">';echo 'alert($line)';echo '</script>';
fwrite ($fh, "$line \n");
$n = $line;
}
else {
fwrite ($fh, "$_POST[n] \n");
$n = $_POST[n];
}
fclose ($fh);
$script = $_SERVER['PHP_SELF'];
print <<<TOP
<html>
<body>
<form method = "post" action = "$script">
<table border = "1">
<tr>
<td> Name</td>
<td> <input type = "text" value = "$n" name = "n" size = "30" /></td>
</tr>
TOP;
print <<<BOTTOM
<tr><td><input type = "submit" name = "order" value = "Submit Order" /></td></tr>
</table></form></body></html>
BOTTOM;
?>
Basically, this has one entry spot which someone can enter into, and once someone enters into it, the data is written to a file. Every time after that the page is loaded, the data should be read from the file and set as the value to the input.
But when I load the program, enter "Word" as the field, and press submit, then open a new tab (to ensure it's not just the data being saved) and reenter the URL, "Word" is echoed as file_get_contents
, but nothing is echoed for echo($line)
and nothing is in the field for the input.
Why is this and how can I fix it?