PHP 简单留言板的制作示例
内容摘要
这篇文章主要为大家详细介绍了PHP 简单留言板的制作示例,具有一定的参考价值,可以用来参考一下。
第一步:在mysql中新建数据库bbs 然后执行sql代码
CREATE TABLE `message` (
第一步:在mysql中新建数据库bbs 然后执行sql代码
CREATE TABLE `message` (
文章正文
这篇文章主要为大家详细介绍了PHP 简单留言板的制作示例,具有一定的参考价值,可以用来参考一下。
第一步:在mysql中新建数据库bbs 然后执行sql代码1 2 3 4 5 6 7 8 9 10 11 12 13 | <code class = "sql" > CREATE TABLE `message` ( `id` tinyint(1) NOT NULL auto_increment, `user` varchar(25) NOT NULL, `title` varchar(50) NOT NULL, `content` tinytext NOT NULL, `lastdate` date NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=gbk AUTO_INCREMENT=1 ; -- 代码来自php教程(www.idcnote.com)</code> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <code class = "php" > <?php $conn = @ mysql_connect( "localhost" , "root" , "" ) or die ( "数据库链接错误" ); mysql_select_db( "bbs" , $conn ); mysql_query( "set names 'GBK'" ); //使用GBK中文编码; function htmtocode( $content ){ $content = str_replace ( "\n" , "<br>" , str_replace ( " " , " " , $content )); return $content ; } ?> /*** 代码来自php教程(www.idcnote.com) ***/ </code> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | <code class = "php" > <?php include ( "conn.php" ); if ( $_POST [ 'submit' ]) { $sql = "insert into message (id,user,title,content,lastdate)" . "values ('','$_POST[user]','$_POST[title]','$_POST[content]',now())" ; mysql_query( $sql ); echo "" ; } ?> <script language= "javascript" > function checkpost() { if (myform.user.value== "" ) { alert( "请输入用户名" ); myform.user.focus(); return false; } if (myform.title.value.length<5) { alert( "标题不能小于5个字符" ); myform.title.focus(); return false; } if (myform.content.value.length<5) { alert( "留言内容不能小于10个字符" ); myform.content.focus(); return false; } } </SCRIPT> <style type= "text/css" > <!-- body,td,th { font-size: 12px; } --> </style> <form name= "myform" action= "add.php" method= "post" onsubmit= "return checkpost();" > <table width= "600" border= "0" align= "center" cellpadding= "0" cellspacing= "1" bgcolor= "#CCCCCC" > <tr> <td height= "26" colspan= "2" align= "center" bgcolor= "#F9F9F9" ><a href= "add.php" >添加留言</a> <a href= "show.php" >查看留言</a> <a href= "login.php" >登陆</a></td> </tr> <tr> <td width= "79" height= "34" align= "center" bgcolor= "#FFFFFF" >用户:</td> <td width= "518" bgcolor= "#FFFFFF" ><label> <input name= "user" type= "text" id= "username" size= "40" > </label></td> </tr> <tr> <td height= "43" align= "center" bgcolor= "#FFFFFF" >标题:</td> <td height= "43" bgcolor= "#FFFFFF" ><input name= "title" type= "text" id= "title" size= "40" /></td> </tr> <tr> <td height= "100" align= "center" bgcolor= "#FFFFFF" >留言:</td> <td height= "100" bgcolor= "#FFFFFF" ><textarea name= "content" cols= "50" rows= "5" id= "content" ></textarea></td> </tr> <tr> <td height= "55" colspan= "2" align= "center" bgcolor= "#FFFFFF" ><label> <input type= "submit" name= "submit" id= "button" value= "提交" > </label></td> </tr> </table> </form> /*** 代码来自php教程(www.idcnote.com) ***/ </code> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | <code class = "php" > <?php include ( "conn.php" ); ?> <?php $sql = "select * from message order by id desc" ; $query =mysql_query( $sql ); while ( $row =mysql_fetch_array( $query )){ ?> <style type= "text/css" > <!-- body,td,th { font-size: 12px; } --> </style> <table width= "1007" border= "0" align= "center" cellpadding= "0" cellspacing= "1" bgcolor= "#CCCCCC" > <tr> <td width= "124" height= "30" align= "center" bgcolor= "#FFFFFF" ><?php echo $row [ "user" ] ?></td> <td width= "880" align= "left" bgcolor= "#FFFFFF" > <?php echo $row [ "title" ] ?><?php echo $row [ "lastdate" ] ?> <a href= "add.php" >添加留言</a> <a href= "show.php" >查看留言</a> <a href= "login.php" >登陆</a></td> </tr> <tr> <td height= "29" bgcolor= "#FFFFFF" ></td> <td align= "left" bgcolor= "#FFFFFF" > <?php echo htmtocode( $row [ "content" ]) ?></td> </tr> </table><br> <?php } ?> /*** 代码来自php教程(www.idcnote.com) ***/ </code> |
1 2 3 4 5 6 7 8 | <code class = "php" > function htmtocode( $content ){ $content = str_replace ( "\n" , "<br>" , str_replace ( " " , " " , $content )); return $content ; /*** 代码来自php教程(www.idcnote.com) ***/ </code> |
1 2 3 4 5 6 7 8 9 10 11 12 13 | <code class = "php" > <?php $conn = @ mysql_connect( "localhost" , "root" , "" ) or die ( "数据库链接错误" ); mysql_select_db( "bbs" , $conn ); mysql_query( "set names 'GBK'" ); //使用GBK中文编码; function htmtocode( $content ){ $content = str_replace ( "\n" , "<br>" , str_replace ( " " , " " , $content )); return $content ; } ?> /*** 代码来自php教程(www.idcnote.com) ***/ </code> |
1 2 | <code class = "php" > <?php echo $row [ "content" ] ?></code> |
1 2 | <code class = "php" > <?php echo htmtocode( $row [ "content" ]) ?></code> |
注:关于PHP 简单留言板的制作示例的内容就先介绍到这里,更多相关文章的可以留意
代码注释