0

所以这是一个简短的故事:我有一个包含用户输入的评论框(我想就像任何常规评论框一样)。我想将此用户输入发送到日志文件。问题是,这没有发生。

这就是我所拥有的:

 if (isset ($_REQUEST['saving'])) {
    $saving = $_REQUEST['saving'];
    if ($saving ==1) {
    $comments = $_POST['comment'];
        $file = "logfile.txt";

    $fp = fopen($file, "w") or die ("Couldn't open $file for writing!");
    fwrite($fp, $comment) or die ("Couldn't write values to file!");

    fclose($fp);
    echo "Saved to $file successfully!";
    }
}

它发送的信息来自:

<textarea name="comment" cols="80" rows="10">
<?php echo $comment; ?>
</textarea><br>

其中 $comment 是用户输入。我没有收到任何错误消息,但是当我打开 logfile.txt 时,它是空的。

任何帮助都会很棒。我真的被困住了。提前感谢所有建议:-)

4

2 回答 2

0
$comments = $_POST['comment'];

应该

$comment = $_POST['comment'];
于 2012-06-11T18:37:28.287 回答
0

fwrite($fp, $comment)应该是fwrite($fp, $comments)。假设您在元素中<textarea>正确放置,这将起作用。<form>

:)

于 2012-06-11T18:35:16.033 回答