| The code is as follows |
Copy Code |
| $con =mysql tutorial _connect ("localhost", "root", "") or Die ("Link error!!! "); mysql_select_db ("message", $con) or Die ("Database link error!!! "); mysql_query ("Set names ' GBK '"); $sql =mysql_query ("SELECT * from message"); if ($_post[button]) { while ($row =mysql_fetch_array ($sql)) { $path = $row [0]. HTML '; $user = $row [1]; $title = $row [2]; $content = $row [3]; $date = $row [4]; $FP =fopen ("moban/html.html", "R"); $str =fread ($fp, FileSize ("./moban/html.html")); $str =str_replace ("{User}", $user, $STR); $str =str_replace ("{title}", $title, $STR); $str =str_replace ("{content}", $content, $STR); $str =str_replace ("{date}", $date, $STR); Fclose ($FP); $handle =fopen ("news/". $path, "w"); Fwrite ($handle, $STR); Fclose ($handle); echo "<script>alert (' Generate success!!! '); window.location.href= ' html.php ';</script> '; } } ?> <!doctype HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/ Xhtml1-transitional.dtd "> <meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/> <title> Untitled Document </title>
<body> <form id= "Form1" Name= "Form1" method= "Post" action= "" > <label> <input type= "Submit" name= "button" id= "button" value= "Generate static page"/> </label> </form> </body>
|
Template file Code
| The code is as follows |
Copy Code |
| <!doctype HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/ Xhtml1-transitional.dtd "> <meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/> <title> Untitled Document </title>
<body> <table width= ">" <tr> <TD width= "><div" align= "right" > name:</div></td> <TD width= "408" ><div align= "left" >{user}</div></td> </tr> <tr> <td><div align= "right" > title:</div></td> <td><div align= "left" >{title}</div></td> </tr> <tr> <td><div align= "Right" > Content:</div></td> <td><div align= "left" >{content}</div></td> </tr> <tr> <td><div align= "Right" > Date:</div></td> <td><div align= "left" >{date}</div></td> </tr> <tr> <td><div align= "right" ></div></td> <td><div align= "left" ></div></td> </tr> </table> </body> |
Delete HTML code
| The code is as follows |
Copy Code |
| <?php $con =mysql_connect ("localhost", "root", "") or Die ("Link error!!! "); mysql_select_db ("message", $con) or Die ("Database link error!!! "); mysql_query ("Set names ' GBK '"); $sql =mysql_query ("SELECT * from message"); if ($_post[button]) { while ($row =mysql_fetch_array ($sql)) { $path = $row [0]. HTML '; if (@unlink ("news/". $path)) { echo <script>alert (' delete successful!!! '); window.location.href= ' unlink_html.php ';</script> '; }else{ echo <script>alert (' no content can delete!!! '); window.location.href= ' unlink_html.php ';</script> '; } } } <form id= "Form1" Name= "Form1" method= "Post" action= "" <label> ; input type= "Submit" name= "button" id= "button" value= "delete static page"/> </label> </form> |
Database structure, you can import it with phpMyAdmin.
The structure ' message ' of the table
--
CREATE TABLE ' message ' (
' ID ' int (4) NOT NULL auto_increment,
' user ' varchar NOT NULL,
' title ' varchar NOT NULL,
' content ' text NOT NULL,
' Date ' date not NULL,
Primary KEY (' ID ')
) Engine=myisam default CHARSET=GBK auto_increment=3;
--
--Export the data in the table ' message '
--
INSERT INTO ' message ' (' id ', ' user ', ' title ', ' content ', ' date ') values
(1, ' DFKK ', ' Database Information generation static page ', ' www.111cn.net ', ' 2010-02-12 '),
(2, ' DFKK ', ' Database Information generation static page ', ' principle is very simple ', ' 2010-02-12 ');
Write it yourself, you can generate static pages through buttons and delete the generated static pages.
Moban Store Template folder (do not delete).
News generates a static page folder (do not delete).
Note: The phpMyAdmin tool imports the database file Message.sql.