濮阳杆衣贸易有限公司

主頁(yè) > 知識(shí)庫(kù) > PHP實(shí)現(xiàn)基本留言板功能原理與步驟詳解

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

熱門標(biāo)簽:濟(jì)源百應(yīng)電銷機(jī)器人聯(lián)系方式 嘟嘟云外呼系統(tǒng) 邢臺(tái)400電話辦理 咸陽(yáng)電銷 南寧電話外呼系統(tǒng)線路 辦理400電話哪家好點(diǎn) 南京3D地圖標(biāo)注 正規(guī)電銷機(jī)器人系統(tǒng) 重慶外呼電銷系統(tǒng)多少錢

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

作為一個(gè)PHP的初學(xué)者,我試著寫了一個(gè)留言板,頁(yè)面有點(diǎn)丑,多多見(jiàn)諒,嘻嘻嘻
#我們寫留言板需要用到數(shù)據(jù)庫(kù),所以我們先要建立三個(gè)表
user表

friend表

text表

#首先需要寫一個(gè)注冊(cè)與登錄

##注冊(cè)
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>用戶注冊(cè)頁(yè)面/h1>
用戶名:input type="text" name="username">
div>密nbsp;nbsp;nbsp;碼:input type="password" name="password">
div>input type="submit" name="submit" value="注冊(cè)">/div>
/div>
/form>
/body>

zhuce.php

?php
session_start();
header("Content-type: text/html; charset=utf-8"); //處理數(shù)據(jù)庫(kù)用戶名亂碼
$user=$_POST["username"];
$pwd=$_POST["password"];
if($user==""||$pwd=="")
	 {
   	echo "script>alert('請(qǐng)確認(rèn)信息完整性!'); history.go(-1);/script>"; 
	 }
else 
  	{
	 		
 			$link=mysqli_connect("localhost","root","","liuyan");//連接數(shù)據(jù)庫(kù)
	 		mysqli_query($link,"set names utf8"); 
	 		$sql="select username from user where username='$_POST[username]'";
    	$result=mysqli_query($link,$sql);//執(zhí)行sql語(yǔ)句
     	$num=mysqli_num_rows($result);//統(tǒng)計(jì)執(zhí)行結(jié)果影響的行數(shù)
     	if($num)//如果存在該用戶
     		{
     			echo "script>alert('用戶名已存在!'); history.go(-1);/script>"; 
    		}
      else//注冊(cè)新用戶
    		 { 
     			$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('注冊(cè)成功!');window.location='denglu.html';/script>"; 
     			}
     			else
     			{
     				echo "script>alert('系統(tǒng)繁忙請(qǐng)重試!'); history.go(-1);/script>"; 
     			}
     	  }
  }
 ?>

#效果如下

##登錄
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>用戶登錄頁(yè)面/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="zhuce.html" rel="external nofollow" >注冊(cè)/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('請(qǐng)輸入用戶名或密碼!'); history.go(-1);/script>"; 
	}
	else
	{
		$link=mysqli_connect("localhost","root","","liuyan");//連接數(shù)據(jù)庫(kù)
    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語(yǔ)句
		$num=mysqli_num_rows($result);//統(tǒng)計(jì)影響結(jié)果行數(shù),作為判斷條件
		if($num)
		{
			echo "script>alert('登錄成功!');window.location='003.php';/script>";//登錄成功頁(yè)面跳轉(zhuǎn) 
		}
		else
		{
			echo "script>alert('用戶名或密碼不正確!');history.go(-1);/script>"; 
	  }
	}
?>

#效果如下

#下面需要我們寫一個(gè)登錄進(jìn)去的頁(yè)面,它顯示別人給你發(fā)來(lái)的留言以及進(jìn)入你要給別人留言的頁(yè)面或者退出系統(tǒng),在這里我將html代碼嵌入php
php代碼如下
003.php

?php
session_start();
global $user;//定義$user
global $user1;
$_SESSION["username"]=$user;
$username=$_SESSION["uesrname"];
$user1=implode("",$_SESSION);//將session中的數(shù)組變?yōu)樽址?
$link=mysqli_connect("localhost","root","","liuyan");//連接數(shù)據(jù)庫(kù)
mysqli_query($link,"set names utf8"); 
$sql="select * from text where recever='{$username}'";
$result=mysqli_query($link,$sql);//執(zhí)行語(yǔ)句
if($num=mysqli_num_rows($result))//將HTML嵌入PHP中,實(shí)現(xiàn)從數(shù)據(jù)庫(kù)中獲得留言信息
{?>
	!DOCTYPE html>
html>
head>
 meta charset="utf-8">
/head>
 body>
 div>
 	a href="fabu.html" rel="external nofollow" >發(fā)布信息/a>nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;
 	a href="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ā)送時(shí)間/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	


}?>

#效果如下

#接下來(lái)我們就該寫發(fā)布的頁(yè)面以及PHP代碼了
fabu.html

head>
	meta charset="utf-8">
	title>fabu/title>
/head>
body>
 form method="POST" action="fabu.php">
h1>發(fā)布信息h1>
a href="003.php" rel="external nofollow" >主頁(yè)面/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

?php
session_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");//獲取時(shí)間,G為24小時(shí)制
$_SESSION["username"]=$user;//開啟session
$user1=implode("",$_SESSION);//將數(shù)組轉(zhuǎn)為字符串
$link=mysqli_connect("localhost","root","","liuyan");//連接數(shù)據(jù)庫(kù)
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í)行語(yǔ)句
$sql1="insert into friend(me,friend) values('$user1','$re')";//將me,friend存入數(shù)據(jù)庫(kù)
$result=mysqli_query($link,$sql1);//執(zhí)行語(yǔ)句
if($recever=""||$comment="")
{
	echo "script>alert('發(fā)布失敗!');window.location='fabu.html';/script>";
}
else
{
	echo "script>alert('發(fā)布成功!');window.location='fabu.html';/script>";
}
?>

#效果如下

#最后是退出系統(tǒng)

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

#效果如下

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

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

您可能感興趣的文章:
  • 使用PHP開發(fā)留言板功能
  • PHP實(shí)現(xiàn)的簡(jiǎn)單留言板功能示例【基于thinkPHP框架】
  • 使用PHP連接數(shù)據(jù)庫(kù)實(shí)現(xiàn)留言板功能的實(shí)例講解(推薦)
  • php+Memcached實(shí)現(xiàn)簡(jiǎn)單留言板功能示例
  • 簡(jiǎn)單實(shí)現(xiàn)PHP留言板功能
  • 基于thinkPHP框架實(shí)現(xiàn)留言板的方法
  • PHP結(jié)合Mysql數(shù)據(jù)庫(kù)實(shí)現(xiàn)留言板功能
  • php實(shí)現(xiàn)網(wǎng)站留言板功能
  • php制作文本式留言板
  • php簡(jiǎn)單的留言板與回復(fù)功能具體實(shí)現(xiàn)
  • php開發(fā)留言板的CRUD(增,刪,改,查)操作
  • php xml留言板 xml存儲(chǔ)數(shù)據(jù)的簡(jiǎn)單例子
  • 來(lái)自經(jīng)典的打造簡(jiǎn)單的PHPMYSQL留言板
  • 一個(gè)簡(jiǎn)單的PHP&MYSQL留言板源碼
  • 一個(gè)可分頁(yè)的基于文本的PHP留言板源碼
  • PHP+MySql實(shí)現(xiàn)一個(gè)簡(jiǎn)單的留言板

標(biāo)簽:河南 黃山 唐山 南通 平頂山 武漢 通遼 隴南

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《PHP實(shí)現(xiàn)基本留言板功能原理與步驟詳解》,本文關(guān)鍵詞  PHP,實(shí)現(xiàn),基本,留言板,功能,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《PHP實(shí)現(xiàn)基本留言板功能原理與步驟詳解》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于PHP實(shí)現(xiàn)基本留言板功能原理與步驟詳解的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    清镇市| 柘荣县| 崇信县| 洱源县| 林西县| 祁连县| 杭锦后旗| 镇巴县| 永善县| 孝昌县| 科尔| 格尔木市| 五台县| 信阳市| 临洮县| 洞口县| 庐江县| 南漳县| 上饶市| 班戈县| 冕宁县| 宜城市| 琼结县| 马关县| 仙居县| 肃宁县| 乐至县| 福州市| 黄陵县| 永康市| 五华县| 水富县| 棋牌| 天等县| 璧山县| 资源县| 奉化市| 酒泉市| 岳阳县| 财经| 金乡县|