在PHP代码中找不到错误(该网站位于挪威,但只是阅读了代码)


Cant find the error in the PHP code (The site is on Norwegian, but just read the code)

a用HTML表单制作了一个"index.php"文件,如下所示:

<form action="send.php" method="get">

该表单有许多文本字段和一个工作正常的提交按钮,但错误出现在名为"send.php"的文档中。请帮助我查找错误!这是代码:(下面)

<?php
                $fileread = fopen('data.txt', 'r');
                $filewrite = fopen('data.txt', 'w');
                $age = $_GET['age'];
                $use = $_GET['use'];
                $sites = $_GET['sites'];
                $connection = $_GET['connection'];
                $service = $_GET['service'];
                $other = $_GET['other'];
                $text = 'Alder: "' . $age . '" Bruk: "' . $use . '" Brukes mest på sider i sjangere, som: "' . $sites . '" Tillkobling: "' . $connection . '" Brukerservice: "' . $service . '" Andre kommentarer fra brukeren: "' . $other . '"';
                $data = fgets($fileread);
                fwrite($data, $filewrite);
                                    fwrite($text, $filewrite);
                echo 'Sendt!';
            ?>

我相信您的fwrite参数已反转。它应该是fwrite($handle,$string);

你应该试试

fwrite($filewrite,$data);
fwrite($filewrite,$text);

不要打开文件两次——一次用于读取,一次用于写入:只需使用打开一次

$filehandle = fopen('data.txt', 'r+');

如果你想在文件末尾附加新数据,只需这样做(你不需要读取文件并重写)

转到文件的末尾

fseek ( $filehandle , 0 ,SEEK_END );

并写入

fwrite($filehandle, $text);

请注意,fwrite的第一个参数是文件句柄,而不是数据。这就是错误。