1、建立conn.php
<?php $bbs=@mysql_connect("127.0.0.1","root","") or die ("Connect False"); mysql_select_db("wikidb",$bbs); mysql_query("set names ‘utf8‘"); ?>
2、建立add.php
<?php include("conn.php"); if(isset($_POST[‘submit‘])){ $sql="INSERT INTO `message`(`id`, `user`, `title`, `content`, `lastdate`) VALUES (‘‘,‘$_POST[user]‘,‘$_POST[title]‘,‘$_POST[content]‘,now())"; mysql_query($sql); echo "<script>alert(‘Successful‘);location.href=‘index.php‘</script>";//删除完成时候返回首页 } ?> <form action="add.php" method="post"> User:<br /> <input type="text" size=10 name="user" /><br /> Title:<br /> <input type="text" name="title" /><br /> Content:<br /> <textarea name="content"></textarea><br /> <input type="submit" name="submit" value="IN"> </form>
3、建立list.php
<?php include("conn.php"); ?> <table width="500" border="1" align="center" callpadding="0" callspacing="0" bgcolor="white"> <?php $sql="SELECT `id`, `user`, `title`, `content`, `lastdate` FROM `message` order by id desc"; $query=mysql_query($sql); while($row=mysql_fetch_array($query)){ ?> <tr bgcolor="yellow"> <td>Title:<?php echo $row[‘title‘]?>User Name:<?php echo $row[‘user‘]?></td> </tr> <tr bgcolor="#ffffff"> <td>Contents:<?php echo $row[‘content‘]?></td> </tr> <?php } ?> </table>
本文出自 “Jerry” 博客,请务必保留此出处http://alipay.blog.51cto.com/7119970/1537553
原文地址:http://alipay.blog.51cto.com/7119970/1537553