zoukankan      html  css  js  c++  java
  • 贴吧小项目3

    cunchu.php存储发送的帖子到客户端

    <?php
    require("./include/init.php");
    
    $sql="insert into thread (username,title,content,pubtime) values ('".$_POST['username']."','".$_POST["title"]."','".$_POST['content']."',".time().")";
    if($_POST['username']==null||$_POST["title"]||$_POST['content']){
        echo "发帖失败,信息不全";
        exit("<a href="index.php">返回重发</a>");
    }
    $rs=mysql_query($sql,$conn);
    $index=mysql_insert_id($conn);
    echo $index;
    if($rs){
        echo "发送成功";
        echo "<a href='chakan.php?tid=".$index."'>查看</a>";
    }
    ?>
    

     chakan.php查看帖子及回复

    <?php
    require("./include/init.php");
    $sql="select username,title,content,pubtime from thread where tid=".$_GET['tid'];
    $arr=getRow($sql,$conn);
    $sql="select tid,username,content,reptime from reply where tid=".$_GET['tid'];
    $list=getALL($sql,$conn);
    ?>
    <!doctype html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>自由发帖</title>
    <link rel="stylesheet" type="text/css" href="./ind.css">
    </head>
    <body>
        <div id="top">
            <ul>
                <li><a href="index.php">回到贴吧首页</a></li>
                <!-- <li><a href="#">22222</a></li>
                <li><a href="#">3333</a></li>
                <li><a href="#">4444</a></li> -->
            </ul>
        </div>
    
        <div class="tiezi">
            <div class="tie">
                <!-- <i class="replynum">0</i> -->
                <h3 class="title"><a href="#"><?php echo $arr["title"]; ?></a></h3>
                <p class="content"><?php echo $arr["content"]; ?></p>
                <div class="info">
                    <li><a href="#"><?php echo $arr["username"]; ?></a></li>
                    <li><a href="#">
                    <?php
                        $ling=date("Y-m-d");
                        $tmp=strtotime($ling);
                        if($arr["pubtime"]>=$tmp){
                            echo date("H:i",$arr["pubtime"]);
                        }else{
                            echo date("m-d",$arr["pubtime"]);
                        }
                     ?>
                    </a></li>
                </div>
    
            </div>
        </div>
        <?php if($list){foreach($list as $v){?>
        <div class="tiezi">
            <p>回复:</p>
            <div class="tie">
                <h3 class="title"><span>回复人:</span><a href="#"><?php echo $v["username"]; ?></a></h3>
                <p class="content"><?php echo $v["content"]; ?></p>
                <div class="info"  style="100px;">
                    <li><span>回复时间</span><a href="#">
                    <?php
                        $ling=date("Y-m-d");
                        $tmp=strtotime($ling);
                        if($v["reptime"]>=$tmp){
                            echo date("H:i",$v["reptime"]);
                        }else{
                            echo date("m-d",$v["reptime"]);
                        }
                     ?>
                     </a></li>
                        }
                </div>
    
            </div>
        </div>
        <?php }}?>
        <div style="margin:0 auto; border:1px solid green; 1000px">
            <form action="cunchu2.php" method="post">
                用户名:<input type="text" name="username"/><br/>
                <input style="display:none;" type="text" value="<?php echo $_GET['tid'];  ?>" name="tid"/><br/>
                内容:<textarea cols="30" rows="6" name="content"></textarea><br/>
                <input type="submit" value="回复" />
            </form>
        </div>
    </body>
    </html>
    

     cunchu2.php将回复的内容存入数据库

    <?php
    require("./include/init.php");
    
    $sql="insert into reply (username,tid,content,reptime) values ('".$_POST['username']."','".$_POST["tid"]."','".$_POST['content']."',".time().")";
    if(($_POST["content"]=="")||$_POST['username']==''){
        echo "回复失败";
    }else{
        $rs=mysql_query($sql,$conn);
        if($rs){
        echo "回复成功";
        
        }
    }
    echo "<a href='chakan.php?tid=".$_POST["tid"]."'>返回</a>";
    // $index=mysql_insert_id($conn);
    // echo $index;
    
    
    ?>
    

     返回查看

  • 相关阅读:
    分享一个小故事
    思维局限
    java程序员笑不死的经历ส้้้้้้้้้
    一些话
    定位 java虚拟机内存问题 个人总结
    关于分布式事务、两阶段提交协议、三阶提交协议(转)
    maven常用配置信息和常量
    Mybatis-常见SQL语句示例
    Redis主从同步原理-SYNC
    B+树在mysql数据库索引中的使用
  • 原文地址:https://www.cnblogs.com/lzzhuany/p/4739866.html
Copyright © 2011-2022 走看看