PHP Implementation message Board function:
1 First login page:
<! DOCTYPE html>
<meta charset= "UTF-8" >
<title> Message Board Login </title>
<script src= "Bootstrap/js/jquery-1.11.2.min.js" ></script>
<script src= "Bootstrap/js/bootstrap.min.js" ></script>
<link href= "Bootstrap/css/bootstrap.min.css" rel= "stylesheet" type= "Text/css"/>
<style>
. header{
margin-left:550px;
margin-top:150px;
height:300px;
max-width:300px;
}
. xiugai{
max-width:200px;
}
. login{
margin-top:10px;
}
</style>
<body>
<form action= "messloginchuli.php" method= "POST" >
<div class= "Header" >
<div class= "Input-group Xiugai" >
<span class= "Input-group-addon" style= "margin-top:20px;" > User name:</span>
<input type= "text" class= "Form-control" name= "UID" placeholder= "Please enter user name" >
</div>
<div class= "Input-group Xiugai" style= "margin-top:10px;" >
<span class= "Input-group-addon" > Password:</span>
<input type= "text" class= "Form-control" name= "pwd" placeholder= "Please enter password" >
</div>
<button type= "Submit" class= "btn btn-success Login" > Login </button>
</div>
</form>
</body>
2 Login page After completion to enter the login processing page, that is, the above submitted to the messloginchuli.php
<?php
Session_Start (); // login to connect the included pages and open the session .
$uid = $_post["UID"];
$pwd = $_post["pwd"];
Require_once "./dbda.class.php";
$db = new Dbda ();
$sql = "Select password from Yuangong where username= ' {$uid} '";
$arr = $db->query ($sql, 0);
Var_dump ($arr [0][0]);
if ($arr [0][0]= $pwd &&!empty ($pwd)) {
$_session["UID"]= $uid;
Header ("location:message.php");
}
?>
Login page Effects
3. After the login is completed, it is to enter the main page, that is, to display the conversation you received, the following is the design of the database table and main page code:
<! DOCTYPE html>
<meta charset= "UTF-8" >
<title></title>
<script src= "Bootstrap/js/jquery-1.11.2.min.js" ></script>
<script src= "Bootstrap/js/bootstrap.min.js" ></script>
<link href= "Bootstrap/css/bootstrap.min.css" rel= "stylesheet" type= "Text/css"/>
<style>
. mess{
max-width:800px;
margin-left:250px;
margin-top:150px;
}
</style>
<body>
<?php
Session_Start ();
$uid = $_session["UID"];
if (Empty ($_session["UID"])) {
Header ("location:messlogin.php");
Exit
}
?>
<div style= "margin-left:880px; margin-top:50px;font-size:20px; ">
<a href= "publish_info.php" > Release information </a>
<a href= "tuichuchuli.php" > Exit system </a>
</div>
<table class= "Table table-bordered mess" style= "Margin-top: -40px;" >
<caption style= "font-size:20px;" >
Message message:
</caption>
<thead>
<tr>
<th> Senders </th>
<th> Send Time </th>
<th> Receivers </th>
<th> Information Content </th>
</tr>
</thead>
<tbody>
<?php
Require_once "./dbda.class.php";
$db = new Dbda ();
$sql = "SELECT * from Liuyan where recever= ' {$uid} ' or recever= ' all ';
$arr = $db->query ($sql, 0);
foreach ($arr as $v) {
echo "<tr>
<td>{$v [1]}</td>
<td>{$v [2]}</td>
<td>{$v [3]}</td>
<td>{$v [4]}</td>
</tr> ";
}
?>
</tbody>
</table>
</body>
Log out of the system to implement user logoff, return to the login page function code as follows:
<?php
Session_Start ();
$uid = $_session["UID"];
Unset ($UID);
Header ("location:messlogin.php");
? >
The code is written here, the more important part is completed, the following is to enter the publishing information page, the equivalent of the previous write the added page, its processing page is not the same as before, the difference is that the current processing page in the case of user login operation, You need to use the session to connect all the pages in the login situation
Main Page effects
4. Finally, the Information publishing page, you can send information to anyone
The code is as follows:
<! DOCTYPE html>
<meta charset= "UTF-8" >
<title> Publishing Information Interface </title>
<script src= "Bootstrap/js/jquery-1.11.2.min.js" ></script>
<script src= "Bootstrap/js/bootstrap.min.js" ></script>
<link href= "Bootstrap/css/bootstrap.min.css" rel= "stylesheet" type= "Text/css"/>
<style>
. mess{
max-width:200px;
margin-top:10px;
}
. mess1{
margin-top:10px;
}
. opt{
max-width:200px;
margin-left:80px;
}
. txt{
max-width:200px;
}
</style>
<body>
<?php
Session_Start ();
$uid = $_session["UID"];
if (Empty ($_session["UID"])) {
Header ("location:messlogin.php");
Exit;
}
?>
<div style= "margin-left:500px; margin-top:150px; " >
<div style= "margin-left:60px; margin-bottom:20px;font-size:20px; ">
<a href= "message.php" > View info </a>
<a href= "seemess.php" style= "margin-left:80px;" > View send Information </a>
</div>
<form class= "form-horizontal" role= "form" action= "infochuli.php" method= "POST" >
<div class= "Form-group" >
<label for= "FirstName" class= "col-sm-2 control-label mess1" > Receiver:</label>
<div class= "Form-group" >
<select class= "Form-control opt" name= "Recever" >
<option value= "All" > Everyone </option>
<?php
Require_once "./dbda.class.php";
$db = new Dbda ();
A SQL statement that can send messages to a specific friend here
$sql = "Select Firend.firend,yuangong.name from Firend,yuangong where firend.firend
= Yuangong.username and firend.me = ' {$uid} ';
$sname = "SELECT * from Yuangong where username not in (' {$uid} ')";
$arr = $db->query ($sname, 0);
Var_dump ($arr [0][2]);
foreach ($arr as $v) {
echo "<option value= ' {$v [0]} ' >{$v [2]}</option>";
}
?>
</select>
</div>
</div>
<div class= "Form-group" >
<label for= "LastName" class= "Col-sm-2 control-label mess1" > Information content:</label>
<div class= "Col-sm-10" >
<textarea class= "Form-control txt" rows= "3" name= "content" ></textarea>
</div>
</div>
<div class= "Form-group" >
<div class= "Col-sm-offset-2 col-sm-10" >
<button type= "Submit" class= "BTN Btn-default" >
Send
</button>
</div>
</div>
</form>
</div>
</body>
Send Information page
5. After completion of the release information to enter the processing page, which is submitted to the infochuli.php, and finally return to send the information interface
<?php
Session_Start ();
$uid = $_session["UID"];
$recever = $_post["Recever"];
$content = $_post["Content"];
$arr = $_post["Recever"];
$t = Date ("y-m-d h:i:s");
Require_once "./dbda.class.php";
$db = new Dbda ();
$sql = "INSERT into Liuyan values (', ' {$uid} ', ' {$t} ', ' {$recever} ', ' {$content} ', 0)";
$arr = $db->query ($sql);
if ($arr &&!empty ($arr)) {
Header ("location:publish_info.php");
}else{
echo "Send failed!";
}
?>
Use PHP to connect to database for message board function