I have the following code that allows the user to put the Timing Status on either On or Off
<html>
<?php
if (isset($_POST['Submit1']))
{
$TimingStat=$_POST['timestat'];
$fileName = 'test.txt';
$lines = file($fileName);
$lines[0]="Timing_status= ". $TimingStat;
file_put_contents($fileName, implode($lines));
fclose( $fileName);
}
else
{
$TimingStat=explode(" ",$lines[0]);
$TimingStat=$TimingStat[1];
}
?>
<form action="test.php" name="Calculation" method="post">
Timing Status: <select selected="selected" name="timestat" VALUE="<?PHP print $TimingStat ; ?>">
<?php $attr= 'selected="selected"'; ?>
<option VALUE="On" <?php echo $TimingStat == 'On' ? $attr : ''; ?>>On</option>
<option VALUE="Off" <?php echo $TimingStat== 'Off' ? $attr : ''; ?>>Off</option>
</select>
<Input Type = "Submit" Name = "Submit1" Value = "Save Parameters">
</form>
</html>
It is important for me that the values be written in a text file and then the code reads from a text file.
Everything works fine, except when I refresh my page the selected value will always go to On although Off has been pressed. Any help would be appreciated. Thank you