|
<? Php
Session_start ();
$ Con = mysql_connect ('localhost', 'root', 'root') or die ('database connection failed! ');
Mysql_query ('set names utf8 ');
Mysql_select_db ('guestbook ');
$ Pagesize = 10; // The number of message records displayed on each page
If (isset ($ _ GET ['Page']) & $ _ GET ['Page']! = '') $ Page = $ _ GET ['Page'];
Else $ page = 0;
$ SQL = "SELECT a. *, B. name, B. email, B. qq, c. revert_time, c. revert
FROM post
Left join revert c ON (a. id = c. post_id), guest B
WHERE a. guest_id = B. id
Order by a. id DESC ";
$ NumRecord = mysql_num_rows (mysql_query ($ SQL ));
$ Totalpage = ceil ($ numRecord/$ pagesize );
$ RecordSql = $ SQL. "LIMIT". $ page * $ pagesize. ",". $ pagesize;
$ Result = mysql_query ($ recordSql );
?>
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = utf-8"/>
<Title> PHPiask simple message board </title>
<Style type = "text/css">
<! --
Body {
Margin-left: 0px;
Margin-top: 0px;
}
A: link {
Text-decoration: none;
Color: # FF6600;
}
A: visited {
Text-decoration: none;
}
A: hover {
Text-decoration: underline;
}
A: active {
Text-decoration: none;
}
. STYLE1 {
Color: # FFFFFF;
Font-weight: bold;
Font-size: 16px;
}
Td {
Font-size: 12px;
}
. Tdhx {
Font-style: italic;
Line-height: 1.5;
Text-decoration: underline;
}
-->
</Style>
<Script language = "javascript">
Function checkInput (){
Var Email = document. getElementById ('email ');
Var QQ = document. getElementById ('QQ ');
Var name = document. getElementById ('name ');
Var post = document. getElementById ('post ');
// Authentication username: cannot exceed 10 characters (5 Chinese characters), cannot enter invalid characters, cannot be blank
NameValue = name. value. replace (/s +/g ,"");
Var SPECIAL_STR = "~! % ^ & * (); "?> <[] {}\|,:/= + -";
Var nameflag = true;
For (I = 0; I <nameValue. lenght; I ++ ){
If (SPECIAL_STR.indexOf (nameValue. charAt (I ))! =-1)
Nameflag = false;
}
If (nameValue = ''){
Alert ('enter the user name! ');
Return false;
}
If (nameValue. length> 10 ){
Alert ('The user name can contain up to 10 characters (5 Chinese characters )! ');
Return false;
}
If (nameflag === false ){
Alert ('user name cannot contain invalid characters. Please change it! ');
Return false;
}
// Verify the QQ number
Var par =/^ [1-9] d {4, 12} $ /;
If (QQ. value! = ''&&! Par. test (QQ. value )){
Alert ('Enter the correct QQ number ');
Return false;
}
// Verify the Email address
Var emailpar =/^ [w-] + (. [w-] +) * @ [w-] + (. [w-] +) + $ /;
If (Email. value! = ''&&! Emailpar. test (Email. value )){
Alert ('Enter the correct email address! ');
Return false;
}
If (QQ. value = ''& Email. value = ''){
Alert ('mailbox and QQ are mandatory ');
Return false;
}
If (post. value = ""){
Alert ('Enter the message content! ');
Return false;
}
If (post. value. length> 400 ){
Alert ('the message content is too long! ');
Return false;
}
}
</Script>
</Head>
<Body>
<Table width = "800" border = "0" align = "center">
<Tr>
<Td height = "80" bgcolor = "#003366"> <span class = "STYLE1"> simple message board tutorial (<a href = "http://www.phpiask.com"> PHP iask </a>) </span> </td>
</Tr>
<Tr>
<Td height = "5" bgcolor = "# efefef"> </td>
</Tr>
</Table>
<Table width = "800" border = "0" align = "center" bgcolor = "# fefefe">
<? Php
While ($ rs = mysql_fetch_object ($ result )){
?>
<Tr>
<Td class = "tdhx"> Contact: <? Php echo $ rs-> name?> | Email: <? Php echo $ rs-> email?> | QQ: <? Php echo $ rs-> qq?> | Message Time: <? Php echo date ("Y-m-d H: I: s", $ rs-> post_time + 8*3600)?> </Td>
</Tr>
<? Php
If (isset ($ _ SESSION ['login']) & $ _ SESSION ['login']) {
?>
<Tr>
<Td class = "tdhx"> <a href = "revert. php? Id = <? Php echo $ rs-> id?> "> Reply </a> | <a href =" delete. php? Id = <? Php echo $ rs-> id?> "> Delete </a> </td>
</Tr>
<? Php
}
?>
<Tr>
<Td> message content: <? Php echo nl2br (htmlspecialchars ($ rs-> post)?> <Br/>
<Font color = "Red">
Reply content: <? Php echo nl2br (htmlspecialchars ($ rs-> revert)?> [<? Php if ($ rs-> revert_time! = "") Echo date ("Y-m-d H: I: s", $ rs-> revert_time + 8*3600)?> ]
</Font>
</Td>
</Tr>
<Tr> <td height = "3px" bgcolor = "# FF6600"> </td> </tr>
<? Php
}
?>
</Table>
<Table width = "800" border = "0" align = "center" bgcolor = "# B1C3D9">
<Tr>
<Td>
<? Php
If ($ page> 0) echo "<a href = 'index. php? Page = ". ($ page-1)." '> Previous page | </a> ";
If ($ page <$ totalpage-1) echo "<a href = 'index. php? Page = ". ($ page + 1)." '> Next page </a> ";
?> </Td>
</Tr>
</Table> <form action = "post. php" method = "post" id = "postForm" name = "postForm">
<Table width = "800" border = "0" align = "center" cellspacing = "1" bgcolor = "# efefef">
<Tr>
<Td width = "117" bgcolor = "# FFFFFF"> Name: </td>
<Td width = "673" bgcolor = "# FFFFFF"> <label>
<Input type = "text" name = "name" id = "name"/>
</Label> </td>
</Tr>
<Tr>
<Td bgcolor = "# FFFFFF"> Email: </td>
<Td bgcolor = "# FFFFFF"> <label>
<Input type = "text" name = "email" id = "email"/>
</Label> </td>
</Tr>
<Tr>
<Td bgcolor = "# FFFFFF"> QQ: </td>
<Td bgcolor = "# FFFFFF"> <label>
<Input type = "text" name = "qq" id = "qq"/>
</Label> </td>
</Tr>
<Tr>
<Td colspan = "2" bgcolor = "# FFFFFF"> Message Content: </td>
</Tr>
<Tr>
<Td colspan = "2" bgcolor = "# FFFFFF"> <label>
<Textarea name = "post" id = "post" cols = "40" rows = "5"> </textarea>
</Label> </td>
</Tr>
<Tr>
<Td colspan = "2" bgcolor = "# FFFFFF"> <label>
<Input type = "submit" name = "Submit" value = "submit" onclick = "return checkInput ();"/>
& Nbsp;
<Input type = "reset" name = "Submit2" value = "reset"/>
</Label> <a href = "login. php"> administrator logon </a> </td>
</Tr>
</Table> </form>
</Body>
</Html>
Post. Php file
<? Php
Header ('content-type: text/html; charset = utf-8 ');
// Escape these values if the PHP automatic escape function is not enabled
If (! Get_magic_quotes_gpc ()){
Foreach ($ _ POST as & $ items ){
$ Items = addslashes ($ items );
}
}
$ Name = $ _ POST ['name'];
$ Qq =$ _ POST ['QQ'];
$ Email = $ _ POST ['email '];
$ Post = $ _ POST ['post'];
If ($ name = "" | strlen ($ name)> 10 ){
Echo <tem
<Script language = "javascript">
Alert ('Enter the correct account name ');
History. go (-1 );
</Script>
Tem;
Exit ();
}
If ($ qq = "" & $ email = ""){
Echo <tem
<Script>
Alert (either 'email or QQ is required! ');
History. go (-1 );
</Script>
Tem;
Exit ();
}
If ($ qq! = ""&&(! Is_numeric ($ qq) | $ qq> 9999999999 | $ qq <= 9999 )){
Echo <tem
<Script>
Alert ("Enter the correct QQ number ");
History. go (-1 );
</Script>
Tem;
Exit ();
}
If ($ email! = ""&&(! Ereg ("^ ([a-zA-Z0-9 _-]) + @ ([a-zA-Z0-9 _-]) + (. [a-zA-Z0-9 _-]) + ", $ email) | strlen ($ email)> 60 )){
Echo <tem
<Script>
Alert ("Enter the correct Email ");
History. go (-1 );
</Script>
Tem;
Exit ();
}
If (strlen ($ post)> 400 ){
Echo <tem
<Script>
Alert ("The entered message is too long! ");
History. go (-1 );
</Script>
Tem;
Exit ();
}
// Link to the database
$ Con = mysql_connect ('localhost', 'root', 'root') or die ('database connection failed! ');
Mysql_query ('set names utf8 ');
Mysql_select_db ('guestbook ');
// Insert customer information into the guest table
$ InsertSql = "insert into guest (name, qq, email) values ('$ name',' $ QQ', '$ email ')";
If (mysql_query ($ insertSql )){
$ Guestid = mysql_insert_id ();
}
Else {
Echo $ insertSql;
Echo mysql_error ();
Echo "data insertion failed! ";
Exit ();
}
// Insert the customer id and message obtained after the above inserts into the post table
$ Post_time = time ();
$ InsertPostSql = "insert into post (guest_id, post, post_time) values ('$ guestid', '$ post',' $ post_time ')";
If (mysql_query ($ insertPostSql )){
Echo <tem
<Script>
Alert ("message succeeded ");
Location. href = "index. php ";
</Script>
Tem;
}
Else {
Echo <tem
<Script>
Alert ("Message failed ");
Location. href = "index. php ";
</Script>
Tem;
}
?> |