这篇文章主要介绍了PHP实现基本留言板功能,结合实例形式分析了PHP实现基本留言板功能的相关原理、数据库构建、功能实现等步骤与相关操作技巧,需要的朋友可以参考下本文实例讲述了PHP实现基本留言板功能的方法。分享给大家供大家参考,具体如下:作为一个PHP的初学者,我试着写了一个留言板,页面有点丑,多多见谅,嘻嘻嘻#我们写留言板需要用到数据库,所以我们先要建立三个表user表friend表text表#首先需要写一个注册与登录##注册zhuce.htmlb
<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
<?phpsession_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<head><meta charset="utf-8"><title>denglu</title></head><body><form method="POST" action="denglu.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><br/><input type="submit" name="submit" value="登录"><a href="zhuce.html" rel="external nofollow" >注册</a></div></form></body>``````objective-cdenglu.php``````phpdenglu.php``````objective-c<?phpsession_start();header("Content-type: text/html; charset=utf-8");global $user;$re=$_POST["recever"];//获取recever$comment=$_POST["neirong"];//获取留言@date_default_timezone_set(PRC);//将数组变为字符串函数$time=date("Y-m-d G:i:s");//获取时间,G为24小时制$_SESSION["username"]=$user;//开启session$user1=implode("",$_SESSION);//将数组转为字符串$link=mysqli_connect("localhost","root","","liuyan");//连接数据库mysqli_query($link,"set names utf8");$sql="insert into text(sender,recever,comment,time) values('$user1','$re','$comment','$time')";$result=mysqli_query($link,$sql);//执行语句$sql1="insert into friend(me,friend) values('$user1','$re')";//将me,friend存入数据库$result=mysqli_query($link,$sql1);//执行语句if($recever=""||$comment=""){echo "<script>alert('发布失败!');window.location='fabu.html';</script>";}else{echo "<script>alert('发布成功!');window.location='fabu.html';</script>";}?>
相关推荐
© 2020 asciim码
人生就是一场修行