php留言板

Posted 请叫我魔术先生

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php留言板相关的知识,希望对你有一定的参考价值。

login.php
<
form action="loginchuli.php" method="post"> <div>用户名:<input type="text" name="uid" /></div> <div>密码:<input type="text" name="pwd" /></div> <input type="submit" value="登录" /> </form>
loginchuli.php
<?php session_start(); $uid = $_POST["uid"]; $pwd = $_POST["pwd"]; include("../DBDA.php"); $db = new DBDA(); $sql = "select count(*) from yuangong where UserName=‘{$uid}‘ and PassWord = ‘{$pwd}‘"; $z = $db->StrQuery($sql); if($z == 1) { $_SESSION["uid"] = $uid; header("location:main.php"); } else { header("location:login.php"); }
main.php
<
br /><br /> <a href="fabu.php">发布信息</a> <a href="tuichu.php">退出系统</a> <br /> <br /> <table width="100%" border="1" cellpadding="0" cellspacing="0"> <tr> <td>发送人</td> <td>发送时间</td> <td>接收人</td> <td>信息内容</td> </tr> <?php session_start(); if(empty($_SESSION["uid"])) { header("location:login.php"); exit; } $uid = $_SESSION["uid"]; include("../DBDA.php"); $db = new DBDA(); $sql = "select * from liuyan where recever=‘{$uid}‘ or recever=‘suoyou‘"; $attr = $db->Query($sql); foreach($attr as $v) { //处理发送者姓名 $sqlname = "select Name from yuangong where username=‘{$v[1]}‘"; $name = $db->StrQuery($sqlname); //处理接收者姓名 $jieshou = ""; if($v[2]=="suoyou") { $jieshou = "所有人"; } else { $sqln = "select Name from yuangong where username=‘{$uid}‘"; $jieshou = $db->StrQuery($sqln); } echo "<tr> <td>{$name}</td> <td>{$v[3]}</td> <td>{$jieshou}</td> <td>{$v[4]}</td> </tr>"; } ?> </table>
<?php
session_start();

if(empty($_SESSION["uid"]))
{
    header("location:login.php");
    exit;
}

$uid = $_SESSION["uid"];
include("../DBDA.php");
$db = new DBDA();

?>
<br /><br />
<a href="main.php">查看信息</a> <a href="tuichu.php">退出系统</a>

<br />
<h2>信息发送</h2>

<form action="fschuli.php" method="post">
<div>接收人:
    <select name="jieshou">
        <option value="suoyou">所有人</option>
        <?php
            $sql = "select firend from firend where me=‘{$uid}‘";
            $attr = $db->Query($sql);
            
            foreach($attr as $v)
            {
                $sqln = "select Name from yuangong where username=‘{$v[0]}‘";
                $name = $db->StrQuery($sqln);
                
                echo "<option value=‘{$v[0]}‘>{$name}</option>";
            }
            
        ?>
    </select>
</div>
<br />
<div>
    信息内容:
    <textarea name="neirong">
    </textarea>
</div>
<br />
<div>
    <input type="submit" value="发送" />
    <input type="reset" value="复位" />
</div>
</form>
<?php
session_start();

if(empty($_SESSION["uid"]))
{
    header("location:login.php");
    exit;
}

$uid = $_SESSION["uid"];
include("../DBDA.php");
$db = new DBDA();

?>
<br /><br />
<a href="main.php">查看信息</a> <a href="tuichu.php">退出系统</a>

<br />
<h2>信息发送</h2>

<form action="fschuli.php" method="post">
<div>接收人:
    <select name="jieshou">
        <option value="suoyou">所有人</option>
        <?php
            $sql = "select firend from firend where me=‘{$uid}‘";
            $attr = $db->Query($sql);
            
            foreach($attr as $v)
            {
                $sqln = "select Name from yuangong where username=‘{$v[0]}‘";
                $name = $db->StrQuery($sqln);
                
                echo "<option value=‘{$v[0]}‘>{$name}</option>";
            }
            
        ?>
    </select>
</div>
<br />
<div>
    信息内容:
    <textarea name="neirong">
    </textarea>
</div>
<br />
<div>
    <input type="submit" value="发送" />
    <input type="reset" value="复位" />
</div>
</form>
fabu.php
<?
php session_start(); if(empty($_SESSION["uid"])) { header("location:login.php"); exit; } $uid = $_SESSION["uid"]; include("../DBDA.php"); $db = new DBDA(); ?> <br /><br /> <a href="main.php">查看信息</a> <a href="tuichu.php">退出系统</a> <br /> <h2>信息发送</h2> <form action="fschuli.php" method="post"> <div>接收人: <select name="jieshou"> <option value="suoyou">所有人</option> <?php $sql = "select firend from firend where me=‘{$uid}‘"; $attr = $db->Query($sql); foreach($attr as $v) { $sqln = "select Name from yuangong where username=‘{$v[0]}‘"; $name = $db->StrQuery($sqln); echo "<option value=‘{$v[0]}‘>{$name}</option>"; } ?> </select> </div> <br /> <div> 信息内容: <textarea name="neirong"> </textarea> </div> <br /> <div> <input type="submit" value="发送" /> <input type="reset" value="复位" /> </div> </form>
fschuli.php
<?php session_start(); include("../DBDA.php"); $db = new DBDA(); $jieshou = $_POST["jieshou"]; $neirong = $_POST["neirong"]; $uid = $_SESSION["uid"]; $time = date("Y-m-d H:i:s"); $sql = "insert into liuyan values(‘‘,‘{$uid}‘,‘{$jieshou}‘,‘{$time}‘,‘{$neirong}‘,false)"; if($db->Query($sql,0)) { header("location:fabu.php"); } else { echo "发布失败!"; }
tuichu.php
<?php session_start(); unset($_SESSION["uid"]); header("location:login.php");

 

以上是关于php留言板的主要内容,如果未能解决你的问题,请参考以下文章

php+mysql实现留言板

超级有用的9个PHP代码片段

PHP初级练习实战之公司留言板(原生)

PHP必用代码片段

PHP代码-psysh调试代码片段工具

超实用的php代码片段