我有以下代码,允许用户将时间状态置于开或关
<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>
对我来说,重要的是将值写入文本文件,然后代码从文本文件中读取。
一切正常,除非我刷新页面时所选的值将始终显示为On,尽管已按下Off。任何帮助,将不胜感激。谢谢