一个超级简单php的留言板

第一步:配置好测试环境;(详细略了)

第二部:新建一个数据库,命名为guestbook(名字可以随便改),可以直接在phpmyadmin里面操作,在数据库里面新建一张表‘content’,表里面有4个字段:id,name,email,content。也可以写sql语句运行。

CREATE TABLE IF NOT EXISTS `content` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(20) NOT NULL,
`email` varchar(50) NOT NULL,
`content` varchar(200) NOT NULL,
PRIMARY KEY (`id`)
)

第三步:新建一个config.php,链接数据库的

<?php 
   $q=mysql_connect("localhost","root",""); 
   if(!$q){
       die('亲,链接不到数据库哦!'.mysql_error());
       }
    mysql_query("set name utf8");       //以utf8读取数据库
    mysql_select_db("guestbook",$q);   //数据库
?>

第四步:新建一个liuyan.php,填写留言信息的

<table width="678" align="center">
  <tr>
    <td colspan="2"><h1>留言本</h1></td>
  </tr>
  <tr>
    <td width="586"><a href="index.php">首页</a> | <a href="liuyan.php">留言</a></td>
  </tr>
</table>
<table align="center" width="678">
  <tr>
    <td><form name="form1" method="post" action="post.php">
        <p> Name:
          <input name="name" type="text" id="name">
        </p>
        <p>Email:
          <input type="test" name="email" id="email">
        </p>
        <p> 留言: </p>
        <p>
          <textarea name="content" id="content" cols="45" rows="5"></textarea>
        </p>
        <p>
          <input type="submit" name="button" id="button" value="提交">
          <input type="reset" name="button2" id="button2" value="重置">
        </p>
      </form></td>
  </tr>
</table>

 

第五步:新建一个post.php,用post方法提交

<?php
include("config.php");
$name= $_POST['name'];
$email= $_POST['email'];
$patch = $_POST['content'];
$content = str_replace("
","<br />",$patch);
$sql = "insert into content (name,email,content) values ('$name','$email','$content')";
mysql_query($sql);
echo "<script>alert('提交成功!返回首页。');location.href='index.php';</script>";
?>

最后新建一个首页文件index.php输出添加成功的留言信息。

<?php 
  include("config.php"); //链接数据库
  $sql="select * from content";
  $resule=mysql_query($sql, $q);
?>
<table width="678" align="center">
  <tr>
    <td colspan="2"><h1>留言本</h1></td>
  </tr>
  <tr>
    <td width="586"><a href="index.php">首页</a> | <a href="liuyan.php">留言</a></td>
  </tr>
</table>

<p>
<?php
while($row=mysql_fetch_array($resule)){
?>
</p>
<table width="678" border="1" align="center" cellpadding="1" cellspacing="1">
  <tr>
    <td width="178">Name:<?php echo $row[1] ?></td>
    <td width="223">Email:<?php echo $row[2] ?></td>
  </tr>
  <tr>
    <td colspan="4"><?php echo $row[3] ?></td>
  </tr>
  <tr>
</table>
<?php } ?>

最后的最后可以了,感受一下自己的杰作吧

http://jingyan.baidu.com/article/bea41d435b7695b4c51be6f8.html

转载于:https://www.cnblogs.com/csdttnk/p/3185943.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值