输入未发送到日志

时间:2012-06-11 18:32:39

标签: php forms file logging request

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

这就是我所拥有的:

 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时,它是空的。

任何帮助都是G R E A T.我真的被困了。在此先感谢所有建议: - )

2 个答案:

答案 0 :(得分:0)

fwrite($fp, $comment)应为fwrite($fp, $comments)。假设您<textarea>正确位于<form>元素内,这将有效。

:)

答案 1 :(得分:0)

$comments = $_POST['comment'];

应该

$comment = $_POST['comment'];
相关问题