PHP基本写错误,没有得到任何结果

时间:2017-09-27 02:36:27

标签: php python html raspberry-pi

只是想知道这里出了什么问题,在这个问题上已经摸不着头脑了。这是一个由另一个PHP脚本调用的脚本,它可以正常工作,直到它应该将 0.0 写入文件的最后一位。两者 - 1和1 都会写入文件,但不会写入 0.0 。我不知道自己做错了什么。输出文件只是空白。我禁用了最后一位,我完全看到 -1和1 ,但是当我启用 0 部分时,他的文件中没有任何内容。

这些值是整数还是字符?我问这个,因为另一个程序将要读取newfile.txt并取出数据。

<?php
$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");

if ($_POST['leftb'])
{ echo "Left is pressed";
    $txt = "-1 \n";}


else if ($_POST['rightb'])
{ echo "Right is pressed";
    $txt = "1 \n";}


fwrite($myfile, $txt);                                              // Write either -1 or 1 to the file
fclose($myfile);                                                    // Close the file



sleep(2);
$myfile = fopen("newfile.txt", "w") or die("Unable to open file!"); // Open It again
$txt = "0.0 \n";
write($myfile, $txt);                                              // Write 0 to the file

fclose($myfile);

?>

1 个答案:

答案 0 :(得分:1)

你有错误输入

像这样改变。 写($ myfile,$ txt)=&gt; fwrite($ myfile,$ txt)

一切都很好。

在代码的开头

添加两行。

使用error_reporting(E_ALL);

ini_set(&#34; display_errors&#34;,1);

这会告诉你什么是错的。