2013-04-30 58 views
1

嗨,我设法使某种评论框,依赖于使用MySQL数据库和PHP编码。我可以通过在我的服务器上打开它的index.php文件来运行评论框,但是当我尝试使用简单的include_once php代码 将它添加到html页面时,它似乎不起作用。将PHP评论框添加到我的网站

请原谅我,如果我听起来很愚蠢,但这是我第一次使用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> 
+0

PHP不能在HTML页面中执行,你需要有'.php'扩展 – 2013-04-30 05:50:55

+1

是你收到一个错误?你会得到什么错误? – 2013-04-30 05:51:05

+1

您只需要保存页面.php扩展名。不在.html – 2013-04-30 05:54:01

回答

0

试试这个:

include "../connect.php"; 

注意:确保你把正确的pathconnect.php