码迷,mamicode.com
首页 > Web开发 > 详细

网站选修课作业(4.1)

时间:2015-05-17 20:04:07      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:

一:创建一个新的数据库 liuyanban

CREATE DATABASE liuyanban;

二:创建数据库表 message

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=utf8 AUTO_INCREMENT=1 ;

三:建立一个数据库连接文件

<?php
/*
 * 
 * @Authors peng--jun 
 * @Email   1098325951@qq.com
 * @Date    2015-05-17 10:53:44
 * @Link    http://www.cnblogs.com/xs-yqz/
 * @version $Id$
 ==========================================
 */
 header("Content-type: text/html; charset=UTF-8"); 
     $DBHOST = localhost;
    $DBNAME = liuyanban;
    $USER = root;
    $PWD= ‘‘;
    $conn = mysql_connect($DBHOST,$USER,$PWD) or die ( "连接数据库失败" );
    mysql_select_db ( $DBNAME, $conn ) or die ( "失败" );
?>

四:页面代码

 1 <?php
 2 /*
 3  * 
 4  * @Authors peng--jun 
 5  * @Email   1098325951@qq.com
 6  * @Date    2015-05-17 10:51:56
 7  * @Link    http://www.cnblogs.com/xs-yqz/
 8  * @version $Id$
 9  =====================================================
10  */
11  error_reporting(E_ALL ^ E_NOTICE); 
12 include include/connectfig.php;//引入头文件
13 if($_POST[submit]){
14     $sql="insert into message(id,user,title,content,lastdate)values(‘‘,‘$_POST[user]‘,‘$_POST[title]‘,‘$_POST[content]‘,now())";
15     mysql_query($sql);
16 }
17 ?>
18 
19 <!doctype html>
20 <html>
21 <head>
22 <meta charset="UTF-8">
23 <title>简易留言板</title>
24 <link rel="stylesheet" type="text/css" href="css/4_1.css">
25 </head>
26 
27 <body>
28     <div id="div1">
29      
30             <form method="post" id="form" action="4_1.php">
31                 用户:<input type="text" size="10" name="user">
32                 <br>
33                 标题:<input type="text" name="title">
34                 <br>
35                 内容:
36                 <textarea name="content" cols="45" rows="5" name="content"></textarea>
37                 <br>
38                 <input type="submit" name="submit" value="留言" />
39             </form>
40   
41     
42             <table cellpadding="5" cellspacing="1" >
43             <?php
44                 $sql1 = "select * from message order by id desc";//按照id倒叙排列
45                 $query = mysql_query($sql1);
46                 while ($rows = mysql_fetch_array($query)) {
47             ?>
48                 <tr bgcolor="#eff3ff">
49                   <td><b>用户:</b><?php echo $rows[title];?> <b>标题:</b><?php echo $rows[user] ;?> <b>发布时间:</b><?=$rows[lastdate];?>
50                   </td>
51                 </tr>
52                 <tr bgColor="#ffffff">
53                   <td><b>内容:</b><?php echo $rows[content];?></td>
54                 </tr>
55             <?php
56                 }
57             ?>
58             </table>
59     </div>
60 </body>
61 </html>

 

网站选修课作业(4.1)

标签:

原文地址:http://www.cnblogs.com/xs-yqz/p/4510278.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!