嗨,我正在尝试从一个程序运行两个 PHP 函数,这些函数通过按两个 html 表单输入来执行,一个带有 2 个按钮的表格,开始和删除;开始写入文件“打开”,删除写入文件“关闭”,但是当我单击运行中的两个按钮时,两个输出都关闭的 php 脚本请帮助!
有按钮的表。
<html>
<TABLE BORDER="3" CELLPADDING="0" CELLSPACING="10">
<TD>
<table BORDER="3" CELLPADDING="3" CELLSPACING="3">
<TH>Socket 1</th>
<TR></tr>
<TD>Serial Number</TD> <TD>ON/OFF</TD>
<TR></TR>
<TD>Elapsed Time </TD>
<TD><?php
include_once ("statusfileon.php")
?></TD>
<TD><?php
include_once ("statusfileoff.php")
?></td>
<TR></TR>
</TABLE>
</TD>
<TD>
<table BORDER="3" CELLPADDING="3" CELLSPACING="3">
<TH>Socket 2</th>
<TR></tr>
<TD>Serial Number</TD> <TD>ON/OFF</TD>
<TR></TR>
<TD>Elapsed Time</TD> <TD>Start</TD> <TD>Remove</td>
<TR></TR>
</TABLE>
</TD>
</TABLE>
</html>
Satusfileon.php
<?php // statusfileon.php
//Write file if button is clicked
if(isset($_POST['submit'])) {
statusfileon();
}
?>
<?php //Write file function
function statusfileon(){ //File function name.
$fh = fopen("statusfile.txt", 'w') or die("Fail to create file");
//Text which is displayed in file (on).
$text = <<<_END
on
_END;
fwrite($fh, $text) or die("Could not write to file"); // If file location could not be found file isn't writen.
fclose($fh); //Close file.
}
?>
<html>
<!--Button and variable for file permission. -->
<form action="<?=$_SERVER['PHP_SELF'];?>" method="post">
<input type="submit" name="submit" value="Start">
</form>
</html>
状态文件off.php
<?php // statusfileoff.php
//Write file if button is clicked.
if(isset($_POST['submit'])) {
statusfileoff();
}
?>
<?php //Write file function
function statusfileoff(){ //File function name.
$fh = fopen("statusfile.txt", 'w') or die("Fail to create file");
//Text which is displayed in file (off).
$text = <<<_END
off
_END;
fwrite($fh, $text) or die("Could not write to file"); // If file location could not be found file isn't writen.
fclose($fh); //Close file.
}
?>
<html>
<!--Button and variable for file permission. -->
<form action="<?=$_SERVER['PHP_SELF'];?>" method="post">
<input type="submit" name="submit" value="Remove">
</form>
</html>
任何帮助将不胜感激,因为我是编程新手,请原谅任何不良做法,谢谢