av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術(shù)文章
文章詳情頁

PHP實現(xiàn)基本留言板功能原理與步驟詳解

瀏覽:103日期:2022-09-11 08:22:31

本文實例講述了PHP實現(xiàn)基本留言板功能的方法。分享給大家供大家參考,具體如下:

作為一個PHP的初學者,我試著寫了一個留言板,頁面有點丑,多多見諒,嘻嘻嘻#我們寫留言板需要用到數(shù)據(jù)庫,所以我們先要建立三個表user表PHP實現(xiàn)基本留言板功能原理與步驟詳解friend表PHP實現(xiàn)基本留言板功能原理與步驟詳解text表PHP實現(xiàn)基本留言板功能原理與步驟詳解

#首先需要寫一個注冊與登錄

##注冊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>密&nbsp;&nbsp;&nbsp;碼:<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'); //處理數(shù)據(jù)庫用戶名亂碼$user=$_POST['username'];$pwd=$_POST['password'];if($user==''||$pwd=='') { echo '<script>alert(’請確認信息完整性!’); history.go(-1);</script>'; }else { $link=mysqli_connect('localhost','root','','liuyan');//連接數(shù)據(jù)庫 mysqli_query($link,'set names utf8'); $sql='select username from user where username=’$_POST[username]’'; $result=mysqli_query($link,$sql);//執(zhí)行sql語句 $num=mysqli_num_rows($result);//統(tǒng)計執(zhí)行結(jié)果影響的行數(shù) 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(’系統(tǒng)繁忙請重試!’); history.go(-1);</script>'; } } } ?>

#效果如下PHP實現(xiàn)基本留言板功能原理與步驟詳解

##登錄denglu.html

<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>密&nbsp;&nbsp;&nbsp;碼:<input type='password' name='password'></div><br/><input type='submit' name='submit' value='登錄'> <a href='http://m.4tl426be.cn/bcjs/zhuce.html' rel='external nofollow' >注冊</a> </div></form></body>

denglu.php

<?php session_start(); $user=$_POST['username'];$_SESSION['uesrname']=$user;//session超全局變量$pwd=$_POST['password'];//獲取密碼if($user=''||$pwd=''){ echo '<script>alert(’請輸入用戶名或密碼!’); history.go(-1);</script>'; }else{$link=mysqli_connect('localhost','root','','liuyan');//連接數(shù)據(jù)庫 mysqli_query($link,'set names utf8'); $sql = 'select username,password from user where username = ’$_POST[username]’ and password = ’$_POST[password]’'; $result=mysqli_query($link,$sql);//執(zhí)行sql語句$num=mysqli_num_rows($result);//統(tǒng)計影響結(jié)果行數(shù),作為判斷條件if($num){echo '<script>alert(’登錄成功!’);window.location=’003.php’;</script>';//登錄成功頁面跳轉(zhuǎn) }else{echo '<script>alert(’用戶名或密碼不正確!’);history.go(-1);</script>'; }}?>

#效果如下PHP實現(xiàn)基本留言板功能原理與步驟詳解#下面需要我們寫一個登錄進去的頁面,它顯示別人給你發(fā)來的留言以及進入你要給別人留言的頁面或者退出系統(tǒng),在這里我將html代碼嵌入phpphp代碼如下003.php

<?phpsession_start();global $user;//定義$userglobal $user1;$_SESSION['username']=$user;$username=$_SESSION['uesrname'];$user1=implode('',$_SESSION);//將session中的數(shù)組變?yōu)樽址?link=mysqli_connect('localhost','root','','liuyan');//連接數(shù)據(jù)庫mysqli_query($link,'set names utf8'); $sql='select * from text where recever=’{$username}’';$result=mysqli_query($link,$sql);//執(zhí)行語句if($num=mysqli_num_rows($result))//將HTML嵌入PHP中,實現(xiàn)從數(shù)據(jù)庫中獲得留言信息{?><!DOCTYPE html><html><head> <meta charset='utf-8'></head> <body> <div> <a href='http://m.4tl426be.cn/bcjs/fabu.html' rel='external nofollow' >發(fā)布信息</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href='http://m.4tl426be.cn/bcjs/tuichu.php' rel='external nofollow' >退出系統(tǒng)</a></h3></div> <br/><br/> <h2>留言信息:</h2> <table cellpadding='0' cellspacing='0' border='1' width='60%'><tr bgcolor='#8BBCC7'><td>發(fā)送人</td><td>接收人</td><td>發(fā)送時間</td><td>信息內(nèi)容</td><?php echo ’<pre>’;while($row=mysqli_fetch_array($result,MYSQLI_ASSOC)){?><tr bgcolor='#FFFFFF'><td ><?php echo $row[’sender’];?>&nbsp;</td><td >&nbsp;<?php echo $row[’recever’];?>&nbsp;</td><td >&nbsp;<?php echo $row[’comment’];?>&nbsp;</td><td >&nbsp;<?php echo $row[’time’];?>&nbsp;</td> <?php } ?></tr></table></body></html> <?php}?>

#效果如下PHP實現(xiàn)基本留言板功能原理與步驟詳解#接下來我們就該寫發(fā)布的頁面以及PHP代碼了fabu.html

<head><meta charset='utf-8'><title>fabu</title></head><body> <form method='POST' action='fabu.php'><h1>發(fā)布信息<h1><a href='http://m.4tl426be.cn/bcjs/003.php' rel='external nofollow' >主頁面</a><div>接收人:<input type='text' name='recever'></select></div></select></div><br/><div>信息內(nèi)容:<textarea input type='text' name='neirong'></textarea></div><br/><input type='submit' value='發(fā)送'></form>

fabu.php

<?phpsession_start();header('Content-type: text/html; charset=utf-8');global $user;$re=$_POST['recever'];//獲取recever$comment=$_POST['neirong'];//獲取留言@date_default_timezone_set(PRC);//將數(shù)組變?yōu)樽址瘮?shù)$time=date('Y-m-d G:i:s');//獲取時間,G為24小時制$_SESSION['username']=$user;//開啟session$user1=implode('',$_SESSION);//將數(shù)組轉(zhuǎn)為字符串$link=mysqli_connect('localhost','root','','liuyan');//連接數(shù)據(jù)庫mysqli_query($link,'set names utf8'); $sql='insert into text(sender,recever,comment,time) values(’$user1’,’$re’,’$comment’,’$time’)';$result=mysqli_query($link,$sql);//執(zhí)行語句$sql1='insert into friend(me,friend) values(’$user1’,’$re’)';//將me,friend存入數(shù)據(jù)庫$result=mysqli_query($link,$sql1);//執(zhí)行語句if($recever=''||$comment=''){echo '<script>alert(’發(fā)布失敗!’);window.location=’fabu.html’;</script>';}else{echo '<script>alert(’發(fā)布成功!’);window.location=’fabu.html’;</script>';}?>

#效果如下PHP實現(xiàn)基本留言板功能原理與步驟詳解#最后是退出系統(tǒng)

<?phpsession_start();unset($_SESSION['uesrname']);echo '<script>alert(’退出成功!’);window.location=’denglu.html’;</script>'; ?>

#效果如下PHP實現(xiàn)基本留言板功能原理與步驟詳解

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《PHP+MySQL留言板開發(fā)專題》、《php緩存技術(shù)總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結(jié)》、《PHP錯誤與異常處理方法總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計入門教程》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》

希望本文所述對大家PHP程序設(shè)計有所幫助。

標簽: PHP
相關(guān)文章:
主站蜘蛛池模板: 日韩欧美1区2区 | 国产成人在线视频 | 欧美在线一区二区三区 | 2一3sex性hd| 成人免费在线 | 日本污视频 | 日韩在线视频一区 | 男女羞羞的网站 | 91精品国产综合久久婷婷香蕉 | 一区二区三区日韩 | 久久久久国色av免费观看性色 | 欧美日韩国产高清视频 | 操操日 | 超碰97人人人人人蜜桃 | 国产欧美一区二区三区在线播放 | 国产欧美在线播放 | 日本二区| 欧美精品一区二区三区在线播放 | 国产成人精品久久二区二区91 | 男人亚洲天堂 | 性在线 | 99福利 | 青娱乐av| 日韩一区二区三区精品 | 久久亚洲二区 | 91久久精品一区二区三区 | 精品视频久久久久久 | 国产亚洲精品精品国产亚洲综合 | 亚洲第一在线 | 一级大片免费 | 国产激情精品一区二区三区 | 成人国产精品一级毛片视频毛片 | 国产视频二区在线观看 | 人人澡视频 | 521av网站 | 久久精品国产亚洲a | 精品成人在线视频 | 久久久一二三 | 成人免费网站 | 午夜伦4480yy私人影院 | 成年网站在线观看 |