標籤:留言板 製作
1、建立conn.php
<?php[email protected]_connect("127.0.0.1","root","") or die ("Connect False");mysql_select_db("wikidb",$bbs);mysql_query("set names ‘utf8‘");?>
2、建立add.php
<?phpinclude("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
<?phpinclude("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