首先数据库的SQL如下:
-- -- 表的结构 `message` --
`title` varchar(50) character set utf8 NOT NULL, `content` tinytext character set utf8 NOT NULL, `lastdate` date NOT NULL,
PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=gbk AUTO_INCREMENT=11 ;
程序代码如下:
首先创建config.php,代码如下:
mysql_select_db("lyb",$conn); mysql_query("set names utf8"); ?>
然后创建index.php,代码如下:
标题:<input type="text" name="title" /><br /> 内容:<textarea name="content"></textarea><br />
<input type="submit" name="submit" value="提交" /></table> </form>
<?php include("config.php");if($_POST['submit'] && !empty($_POST['title'])&& !empty($_POST['user'])&& !empty($_POST['content']))
{ $sql="insert into message (id,user,title,content,lastdate) values ('','$_POST[user]','$_POST[title]','$_POST[content]',now())";
mysql_query($sql); //echo "成功"; }?>
<table width=500 border="1" align="left" cellpadding="5" cellspacing="1" bgcolor="#add3ef">
<?php $sql="select * from message order by id desc"; $query=mysql_query($sql); while($row=mysql_fetch_array($query)){ ?>
<tr bgcolor="#eff3ff"> <td>标题:<?php echo $row[title];?> 用户:<?php echo $row[user];?></td> </tr> <tr bgColor="#ffffff">
<td>内容:<?php echo $row[content];?></td> </tr>
<?php } ?>
转载请注明转自:运达's blog(原文地址:http://www.yunda51.com/?p=408)
话说更新一下我博客地址吧,http://www.hqqblog.com/
地址已更新,你换域名了啊!
学习了、