我正试图为php网页创建一个评论区域。
我跟踪这视频(我只遵循代码,因为我不知道创建者的语言),而且代码似乎不起作用。
下面是代码的PHP位(修改),运行时错误告诉我出了什么问题。我注释了一些给出错误的行:
<?php
$name = $_POST["name"];
$email = $_POST["email"];
$url = $_POST["url"];
$message = $_POST["message"];
$post = $_POST["post"];
if($post){
$write = fopen("../database/fnaticcomments.txt", "a+");
fwrite($write, "<b>$name<br>$email<br>$url<br></b>$message<br> ");
fclose($write);
$read = fopen("../database/fnaticcomments.txt", "r+t");
echo "All comments:";
while(!feof($read)){
echo fread($read, 1024);
}
fclose($read);
}
else{
// $read = fopen("../database/fnaticcomments.txt", "r+t");
echo "All comments:";
// while(!feof($read)){
// echo fread($read, 1024);
}
fclose($read);
}
?>如果有人能帮我,我会很感激的。
*我所犯的错误是:
(1)警告:fopen(./database/fnatic注释s.txt) function.fopen:未能打开流:在第95行的/home/delpilam/public_html/firstProject/php/fnaticpage.php中拒绝权限
(2)警告: feof()期望参数1是资源,在第98行的/home/delpilam/public_html/firstProject/php/fnaticpage.php中给出布尔值
(3)警告: fread()希望参数1是资源,在第99行的/home/delpilam/public_html/firstProject/php/fnaticpage.php中给出布尔值
发布于 2015-04-07 05:23:04
在其他情况下,如果没有添加注释,则尝试读取不存在的文件,请添加file_exists检查。
尝试如下:
<?php
$name = $_POST["name"];
$email = $_POST["email"];
$url = $_POST["url"];
$message = $_POST["message"];
$post = $_POST["post"];
if($post){
$write = fopen("../database/fnaticcomments.txt", "a+");
fwrite($write, "<b>$name<br>$email<br>$url<br></b>$message<br> ");
fclose($write);
$read = fopen("../database/fnaticcomments.txt", "r+t");
echo "All comments:";
while(!feof($read)){
echo fread($read, 1024);
}
fclose($read);
}
else{
if(file_exists("../database/fnaticcomments.txt")) {
$read = fopen("../database/fnaticcomments.txt", "r+t");
echo "All comments:";
while(!feof($read)){
echo fread($read, 1024);
}
fclose($read);
} else {
echo "No comments";
}
}
?>https://stackoverflow.com/questions/29484187
复制相似问题