加入收藏 | 设为首页 | 会员中心 | 我要投稿 PHP编程网 - 黄冈站长网 (http://www.0713zz.com/)- 数据应用、建站、人体识别、智能机器人、语音技术!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

如何用PHP写一个留言板?实现步骤及代码分享

发布时间:2021-12-23 12:50:27 所属栏目:PHP教程 来源:互联网
导读:这篇文章给大家分享的是如何利用PHP来实现一个简易留言板,下文有实现步骤以及代码的介绍,虽然页面比较简单,但留言板基本功能都有实现,感兴趣的朋友就继续往下看吧。 首先,我们写留言板需要用到数据库,所以我们先要建立三个表 #首先需要写一个注册与登
  这篇文章给大家分享的是如何利用PHP来实现一个简易留言板,下文有实现步骤以及代码的介绍,虽然页面比较简单,但留言板基本功能都有实现,感兴趣的朋友就继续往下看吧。
 
        首先,我们写留言板需要用到数据库,所以我们先要建立三个表
 
 
        #首先需要写一个注册与登录
 
        ##注册
        zhuce.html
 
<meta charset="utf-8">
<title>zhuce</title>
</head>
<body>
<form method="POST" action="zhuce.php">
<div style="margin-left: 500px;margin-top:200px;height: 250px;width: 250px">
<h1>用户注册页面</h1>
用户名:<input type="text" name="username">
<div>密   码:<input type="password" name="password">
<div><input type="submit" name="submit" value="注册"></div>
</div>
</form>
</body>
        zhuce.php
 
<?php
session_start();
header("Content-type: text/html; charset=utf-8"); //处理数据库用户名乱码
$user=$_POST["username"];
$pwd=$_POST["password"];
if($user==""||$pwd=="")
 {
    echo "<script>alert('请确认信息完整性!'); history.go(-1);</script>";
 }
else
   {
 
  $link=mysqli_connect("localhost","root","","liuyan");//连接数据库
  mysqli_query($link,"set names utf8");
  $sql="select username from user where username='$_POST[username]'";
     $result=mysqli_query($link,$sql);//执行sql语句
      $num=mysqli_num_rows($result);//统计执行结果影响的行数
      if($num)//如果存在该用户
      {
      echo "<script>alert('用户名已存在!'); history.go(-1);</script>";
     }
      else//注册新用户
      {
      $sql_insert="insert into user (username,password)values('$_POST[username]','$_POST[password]')";
      $res_insert=mysqli_query($link,$sql_insert);
      if($res_insert)
      {
      echo "<script>alert('注册成功!');window.location='denglu.html';</script>";
      }
      else
      {
      echo "<script>alert('系统繁忙请重试!'); history.go(-1);</script>";
      }
        }
  }
 ?>

(编辑:PHP编程网 - 黄冈站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读