Use PHP to connect to the database to implement the message board function.
PHP implements the message board function:
1 first, the login page:
<! DOCTYPE html>
<Html>
<Head>
<Meta charset = "UTF-8">
<Title> message board logon </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"/>
</Head>
<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">
<H2> internal message board of the Development Department <Div class = "input-group xiugai">
<Span class = "input-group-addon"> // After logon, connect the logon page to enable 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 ");
}
?>
Logon page Effect
3. After logging on to the console, you can view the dialog content you have received. The following figure shows the table and Page code of the database:
<! DOCTYPE html>
<Html>
<Head>
<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"/>
</Head>
<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> log out of the logon system to log out. The code for returning to the logon page is as follows:
<? Php
Session_start ();
$ Uid = $ _ SESSION ["uid"];
Unset ($ uid );
Header ("location: messlogin. php ");
?>
The code is written here, and the more important part is completed. The following is the release information page, which is equivalent to the page added previously. Its processing page is no different from the previous one, the difference is that the current processing page is operated upon user login. You need to use session to connect all the login pages.
Homepage Effect
4. Finally, the Information Publishing Page, which can send information to anyone
The Code is as follows:
<! DOCTYPE html>
<Html>
<Head>
<Meta charset = "UTF-8">
<Title> release information page </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"/>
</Head>
<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>
5. After the publishing information is complete, enter the processing page, that is, the submitted infochuli. php, and finally return the sending 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 "failed to send! ";
}
?>