首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为PHP网页创建注释部分

问为PHP网页创建注释部分
EN

Stack Overflow用户
提问于 2015-04-07 05:09:48
回答 1查看 968关注 0票数 0

我正试图为php网页创建一个评论区域。

我跟踪这视频(我只遵循代码,因为我不知道创建者的语言),而且代码似乎不起作用。

下面是代码的PHP位(修改),运行时错误告诉我出了什么问题。我注释了一些给出错误的行:

代码语言:javascript
复制
<?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中给出布尔值

EN

回答 1

Stack Overflow用户

发布于 2015-04-07 05:23:04

在其他情况下,如果没有添加注释,则尝试读取不存在的文件,请添加file_exists检查。

尝试如下:

代码语言:javascript
复制
<?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";
         }

        }
        ?>
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29484187

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档