• 删除留言和更新留言——在线留言板3


    删除留言总体上比较简单,就是从数据库中删除相应的数据然后回到主页就好了。

    <?php
        require_once("sys_conf.inc");
    
        //连接数据库
        $link_id=mysql_connect($DBHOST,$DBUSER,$DBPWD);            
        mysql_select_db($DBNAME);              //选择数据库my_chat
    
        //删除留言数据
        $str="delete from guestbook ";
        $str=$str."where rid=".$_GET["recordid"];
        //echo $str;
        $result=mysql_query($str,$link_id); //执行查询 
    
        //删除回复数据
        $str="delete from reply ";
        $str=$str."where bookidid=".$_GET["recordid"];
        //echo $str;
        $result=mysql_query($str,$link_id); //执行查询 
    
        mysql_close($link_id); 
    
        //返回search.php页面
        echo "<script language='javascript'>";
        echo " location='booklist.php?keyword=&search=1'";
        echo "</script>";   
    ?>

    更新留言的话涉及到取主键的问题,但和插入留言还是有太多相似的地方呢。

    <!--update.php:修改留言信息--------------->
    
    <?php
    
    
    //修改完毕后,返回guest页面
    if(!isset($_GET["recordid"]) or $_GET["recordid"]=="")
    {
        echo "<script language='javascript'>";
        echo " location='booklist.php?keyword=&search=1'";
        echo "</script>";
    }
    else {
    
        require_once("sys_conf.inc");
    //初始化页面表单中的值
    //连接数据库
        $link_id = mysql_connect($DBHOST, $DBUSER, $DBPWD);
        mysql_select_db($DBNAME);                //选择数据库my_chat
        $str = "select name,homepage,location,email,message,content from guestbook where rid=" . $_GET["recordid"];
    //echo $str;
        $result = mysql_query($str, $link_id);
        list($name2, $homepage2, $location2, $email2, $message2, $content2) = mysql_fetch_row($result);
    
    //判断姓名和留言信息是否为空
        $errorm = "";
        if (isset($_POST['name']) or isset($_POST['message'])) {
    //  if (!isset($message) or $message=="" or !isset($name) or $name=="")
            if ($_POST['name'] == "" or $_POST['message'] == "") {
                $errorm = "<font color=red>出错了!!!</font>姓名和留言内容必填";
            } else {
                //获取并处理用户提交信息
                $space = "&nbsp;";
                $time = date("Y年m月d日H小时i分");
                $ip = $_SERVER['REMOTE_ADDR'];
    
                $message = $_POST['message'];
                $name = $_POST['name'];
                $homepage = $_POST['homepage'];
                $email = $_POST['email'];
                $location = $_POST['location'];
                $recordid=$_POST['recordid'];
    
                $message = StripSlashes($message);        //给字符串中按照需要加上""和去掉"",对于某些数据库,必须在要查询的字符加上和去掉""之后才能够查询.
                $message = htmlspecialchars($message); //将HTML特殊字符换成它们的名字,例如"<"变成"<".
                $message = nl2br($message);                    //在HTML中的每一个回车前面加上"<BR>".
    
                $guestcontent = "<tr><td><font color=#AB00E1>留言内容:</font><br><!--content>$message<!--endcontent> ";
                $guestcontent = $guestcontent . "<br><font color=#6633FF>留言人大名:    </font><!--name>$name<!--endname> ";
                if ($email != "") {
                    $guestcontent = $guestcontent . "<br><font color=#9900CC>电子信箱:</font><a href="mailto:$email"><!--email>$email<!--endemail></a>" . "$space";
                }
                if ($homepage != "http://") {
                    $guestcontent = $guestcontent . "<font color=#9900CC>主页:</font>$homepage<a href="$homepage"><!--homepage>$homepage<!--endhomepage></a>";
                }
                if ($location != "")
                    $guestcontent = $guestcontent . "<br><font color=#0000FF>时间:$time 来自:$location $ip</font>";
                $guestcontent = ereg_replace(chr(10), "", $guestcontent);
                $guestcontent = $guestcontent . "<hr size=1></td></tr>
    ";
    
                //修改数据库
                $str = "update guestbook set";
                $str = $str . "time='$time',ip='$ip',name='$name',homepage='$homepage',";
                $str = $str . "location='$location',email='$email',content='$guestcontent')";
                $str = $str . "where rid=$recordid";
                echo $str;
                $result = mysql_query($str, $link_id); //执行查询
    
                mysql_close($link_id);
            }
        }
    }
    ?>
    
    <html>
    <style type=text/css>
        Td {FONT-SIZE: 10pt;}
        TEXTAREA
        {
            FONT-FAMILY: "宋体";
            FONT-SIZE: 10pt;
        }
    </style>
    <head>
        <title>修改留言</title>
    </head>
    
    <body bgcolor=#FFFFFD>
    <?php include  "head.html"?>
    <div align="center">
        <table width="68%" border="1" cellpadding="3" cellspacing="0" bordercolor="#E3E3E3">
            <form method="POST" action="update.php">
                <?
                //如果输入的用户名或留言信息为空,则报错
                if ($errorm)
                {
                    echo "<tr>";
                    echo "<td colspan=3 height=32> ";
                    echo "$errorm";
                    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" value="<?php echo "$name2"?>" size="40">
                        </font></td>
                </tr>
                <tr>
                    <td width="22%" height="29">主页:</td>
                    <td colspan="2" height="29" width="78%">
                        <input type="text" name="homepage" value="<?php echo "$homepage2"?>"size="40">
                    </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" value="<?php echo "$location2"?>" 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" value="<?php echo $email2 ?>" 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"><?php echo $message2 ?></textarea>
                                <!--                            自动换行用wrap-->
                            </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="B1">
                                &nbsp;&nbsp;&nbsp;
                                <input type="reset" value="重 写" name="B2">
                            </font></div>
                    </td>
                </tr>
            </form>
        </table>
    </body>
    </html>
  • 相关阅读:
    TransmitFile
    xml
    鼠标划过表格行变色-简洁实现
    关于表变量
    显式接口成员实现
    华为致新员工书
    C#实现的堆栈
    Gridview中合并单元格,某字段的内容相同时如何只显示一个,屏蔽相同列或行的内容(转)
    ASP.NET 验证控件
    动态SQL EXEC
  • 原文地址:https://www.cnblogs.com/zjunet/p/4559917.html
Copyright © 2020-2023  润新知