将PHP评论框添加到我的网站

时间:2013-04-30 05:47:50

标签: php

您好我已经设法制作了一些依赖于使用mysql数据库和php编码的评论框。我可以通过在我的服务器上打开它的index.php文件来运行评论框但是当我尝试使用简单的include_once php代码将其添加到html页面时 它似乎不起作用。

请原谅我,如果我听起来很愚蠢,但这是我第一次使用php。

这是我一直试图使用的代码。

   <?php
   include_once("../connect.php");
   $commenting_form = '<form action="addcomment.php" method="post">
   <table width="310" border="0" cellspacing="0" cellpadding="0">
     <tr>
       <td colspan="2"><strong>Add Comment:</strong></td>
     </tr>
     <tr>
       <td width="105">Title</td>
       <td width="205"><input type="text" name="msg_title" id="msg_title" style="width:200px;" /></td>
     </tr>
     <tr>
       <td colspan="2"><textarea name="msg_message" id="msg_message" style="width:100%;height:200px;font-family:Courier New">Message</textarea></td>
     </tr>
     <tr>
       <td colspan="2" align="center"><input type="submit" value="Add Comment" name="msg_submit" id="msg_submit" /></td>
     </tr>
   </table>
   </form>';
   $get_comments = mysql_query("SELECT * FROM comments");
   $comments_count = mysql_num_rows($get_comments);
   if ($comments_count>0)
   {
    while ($com = mysql_fetch_array($get_comments))
    {
        $id = $com['id'];
        $title = $com['text'];
        $message = $com['message'];
        $comment .= '<strong>'.$title.'</strong><br />'.$message.'<hr />';
    }
    $comment .= $commenting_form;
    $page_title = $comments_count.' Comments';
   }
   else
   {
    $comment = 'There are no comments at the moment.<br />'.$commenting_form;
    $page_title = 'No Comments';
   }

   ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"               "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
   <html xmlns="http://www.w3.org/1999/xhtml">
   <head>
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
   <title><?php echo $page_title; ?></title>
   </head>

   <body>
   <?php
   echo $comment;
   ?>

   </body>
   </html>

1 个答案:

答案 0 :(得分:0)

试试这个:

include "../connect.php";

注意:请确保放置path

connect.php