添加评论和查看评论的话,主要在于是在不同的表插入,然后该传递的值是不是用post的方式或者get的方式传递了。
添加:

<!--reply.php:回复留言信息--------------->
<?
    require_once("sys_conf.inc");

    //判断姓名和留言信息是否为空
    $errorm="";
if(isset($_POST["name"]))
{
    if ($_POST["message"]=="" || $_POST["name"]=="")
    {
        $errorm="<font color=red>出错了!!!</font>姓名和留言内容必填";
    }
    else
    {
        //连接数据库
        $link_id=mysql_connect($DBHOST,$DBUSER,$DBPWD);
        mysql_select_db($DBNAME);              //选择数据库my_chat

        $bookid=$_POST["recordid"];
        $message = $_POST['message'];
        $name = $_POST['name'];
        $homepage = $_POST['homepage'];
        $email = $_POST['email'];
        $location = $_POST['location'];


        $space = "&nbsp;";
        $time = date("Y年m月d日H小时i分");
        $ip=$_SERVER["REMOTE_ADDR"];
        $message=StripSlashes($_POST["message"]);    //给字符串中按照需要加上"\"和去掉"\",对于某些数据库,必须在要查询的字符加上和去掉"\"之后才能够查询.
        $message=htmlspecialchars($message); //将HTML特殊字符换成它们的名字,例如"<"变成"<".
        $message=nl2br($message);         //在HTML中的每一个回车前面加上"<BR>".

        $guestcontent = "<tr><td><font color=#AB00E1>回复内容:</font><br>$message";
        $guestcontent=$guestcontent."<br><font color=#6633FF>回复人大名:  </font>".$_POST["name"];
        if ($_POST["email"] !="")
            $guestcontent=$guestcontent."<br><font color=#9900CC>电子信箱:</font><a href=\"mailto:".$_POST["email"]."\">".$_POST["email"]."</a>"."$space";
        if ($_POST["homepage"] !="http://")
            $guestcontent=$guestcontent."<font color=#9900CC>主页:</font><a href=\"$homepage\">$homepage</a>";
        if ($_POST["location"] !="")
            $guestcontent=$guestcontent."<br><font color=#0000FF>时间:".$time." 来自:".$_POST["location"]."  $ip</font>";
        $guestcontent=ereg_replace(chr(10),"",$guestcontent);
        $guestcontent=$guestcontent."<hr size=1></td></tr>\n";

        //插入数据
        $str="insert into reply (replyid,bookid,time,ip,name,homepage,location,email,message,content,is_delete)";
        $str=$str."values($bookid,$bookid,'$time','$ip','".$_POST["name"]."','".$_POST["homepage"]."','".$_POST["location"]."','".$_POST["email"]."','".$_POST["message"]."','".$guestcontent."','n')";
        //echo $str;
        $result=mysql_query($str); //执行查询
        mysql_close($link_id);

        echo "<script language='javascript'>";
        echo " location='booklist.php?keyword=&search=1'";
        echo "</script>";
    }
}

?>

<title>回复留言</title> 
<style> 
<!-- 
A:link {text-decoration: none ; color:#0000ff}
A:visited {text-decoration: none; color:#004080}
A:active {text-decoration: none} 
A:hover {text-decoration: underline; color:#ff0000}
BODY {FONT-SIZE: 10pt}
TH {FONT-SIZE: 10pt} 
TD {FONT-SIZE: 10pt} 
--> 
</style> 
<body bgcolor="#FFFFFF" background="back.gif"> 
    <?php include  "head.html"?>
<div align=center > 
    <table border= 1    width= 65%  height= 169 cellpadding="8" cellspacing="0" bordercolor="#E3E3E3" > 
        <form method="POST" action="reply.php"> 
            <? 
            if (isset($_POST['ok']) )
             { 
                if ($_POST['name']=="" or $_POST['message']=="")
                { 
                    echo"<tr align=left valign=middle bgcolor=#F0F0F0> "; 
                    echo"<td width= 100%    height= 31 > "; 
                    echo "<font color=red>出错了</font>回复人姓名和回复内容必填!"; 
                    echo"</td>"; 
                    echo"</tr>"; 
                } 
             } 
            ?> 
            <tr>    
            <td width="22%" bgcolor="#F0F0F0"><font color="#000000">姓名<font color="#FF0033">(必填)</font></font></td> 
            <td colspan="2" width="78%" bgcolor="#F0F0F0"><font color="#00FF00">    
                <input type="text" name="name" size="40"> 
                </font></td> 
        </tr> 
        <tr>    
            <td width="22%" height="29">主页:</td> 
            <td colspan="2" height="29" width="78%">    
                <input type="text" name="homepage" size="40" value="http://"> 
            </td> 
        </tr> 
        <tr>    
            <td width="22%" height="27" bgcolor="#F0F0F0">来自:</td> 
            <td colspan="2" height="27" width="78%" bgcolor="#F0F0F0">  
                <input type="text" name="location" size=40">
            </td> 
        </tr> 
        <tr>    
            <td width="22%" height="20">Email:</td> 
            <td colspan="2" height="20" width="78%"><font color="#00FF00">  
                <input type="text" name="email" size="40"> 
                </font></td> 
        </tr> 
        <tr>    
            <td colspan="3" valign="middle" align="left">   
                <div align="center"><font color="#000000">请回复</font><font color="#FF0033">(必填)</font><font color="#00FF00"><br> 
                <textarea rows="6" name="message" cols="55" wrap="VIRTUAL"></textarea> 
                </font></div> 
            </td> 
        </tr> 
        <tr bgcolor="#F0F0F0">  
            <td colspan="3" height="24">    
                <div align="center"><font color="#00FF00">  
                <input type=hidden value=<?php  if(isset($_GET["recordid"])) echo $_GET["recordid"];?> name=recordid>
                <input type="submit" value="提   交" name="ok"> 
                &nbsp;&nbsp;&nbsp;  
                <input type="reset" value="重 写" name="cencel"> 
                </font></div> 
            </td> 
        </tr> 
        </form> 
    </table> 
</div> 
</body> 
</html> 

then 评论列表:

<!--replylist.php:查看回复--------------------->
<?php   
    require_once("sys_conf.inc");
    //初始化
    $one_page_line=10;     //每页的最大记录数
    $reply_content=array();        //数组,包含所有记录的content属性内容

    //查询数据库,获取$content值
    $link_id=mysql_connect($DBHOST,$DBUSER,$DBPWD);            
    mysql_select_db($DBNAME);
    $str="select content from reply where bookid =".$_GET["recordid"];
    $result=mysql_query($str,$link_id);

    //循环将数据库中值写入数组
    $i=0;
    while(list($con)=mysql_fetch_row($result))
    {
        $reply_content[$i]=$con;
        $i++;
    }
    mysql_close($link_id);  

    $count =count($reply_content); 
?>
<html>
    <head>
        <title>查看回复</title>
    </head>
    <body>
        <?php include  "head.html"?>
        <table width="68%" border="0"> 
            <tr> 
            <td>            
            <?php 
            $int_page_count=$count; //总条数; 
            $int_page_num=ceil($int_page_count/$one_page_line);//总页数; 
            echo "<font color=#CC33FF>分页:"; 
            for ($i=1;$i<=$int_page_num;$i++) 
            { 
                    echo "<a href=booklist.php?recordid=".$_GET["recordid"]."&page=$i>".$i."</a>&nbsp;"; 
            } 
            echo "</font>"; 
            ?> 
            </td>
            <td><p align=right>共有<font color=red><?echo "$count"?></font></p></td> 
            </tr>
        </table> 
        <table width="68%" border="0" align="center"> 
        <?
        if (!isset($_GET['page']))
            $page=1;
        else
            $page=$_GET['page'];
        $text="";
        $begin_line=$int_page_count-($page-1)*$one_page_line; 
        if ($begin_line<$one_page_line)
            $one_page_line=$begin_line; 

        for ($j=$begin_line;$j>($begin_line-$one_page_line);$j--) 
        {           
            print_r ($reply_content[$j-1]);
        }
        ?> 
        </table> 
        <p align=center><a href="#" onclick=history.back()>返  回</a></p>
        </body>
</html>
posted on 2015-04-08 12:08  虽然如此  阅读(441)  评论(0编辑  收藏  举报