您的位置:

php做一个留言web,php留言板的简单编写

本文目录一览:

如何用php做出登陆注册留言板

登录页:login.php

?php

include("conn.php");

$username=$_POST['name'];

$password=$_POST['password'];

$yanzheng=$_POST['yanzheng'];

if(isset($_POST['submit']))

{

$sql=("select username,password from member where username='$username' and password='$password'") or die("sql语句执行失败");

//print_r($sql);

$ar=mysql_query($sql);

if($ar)

{

if($row=mysql_fetch_array($ar))

{

session_start();

if($_POST["yanzheng"])

{

if($yanzheng!=$_session[pic]||$yanzheng=="")

{

echo "验证码输入有误";

exit;

}

if($yanzheng==$_session[pic])

{

header("location:index.php");

}

}

}

else

{

echo "用户名或密码错误";

}

}

}

?

form action="login.php" method="post"

table border=1 align=center width=500 height=300 bgColor=#DFFFDF bordercolor=#fffbec

tr

td colspan=2 align=center用户登录/td

/tr

tr

td用户姓名:/td

tdinput type="text" name="name" id="name"//td

/tr

tr

td用户密码:/td

tdinput type="password" name="password" id="password"//td

/tr

tr

td验证码:/td

tdinput type="text" name="yanzheng" id="yanzheng"/

img src="yanzheng1.php" width="50" height="30"/img

/td

/tr

tr

td colspan=3 align=center

input type="submit" name="submit" value="登录"/

input type="reset" name="reset" value="重置"/

a href="register.php"注册/a

/td

/tr

/table

/form

注册页:register.php

?php

include("conn.php");

if(isset($_POST['submit'])$_POST['submit']) {

if($_POST['username']=='')

{

echo "用户名不能为空";

exit();

}

if($_POST['password']=='')

{

echo "密码不能为空";

exit();

}

if($_POST['realpass']!=$_POST['password'])

{

echo "两次密码输入不一致";

exit();

}

$sql="insert into member(username,real_name,password,email,headimg) values('$_POST[username]','$_POST[username]','$_POST[password]','$_POST[email]','')";

$ar=mysql_query($sql);

if($ar)

{

header("location:index.php");

}

else

{

echo mysql_error();

}

}

?

body

form action="register.php" method="post"

table border=1 align=center width=500

tr

td height=40 bgColor=#DFFFDF colspan=2会员注册          [a href="login.php"返回登录页/a]/td

/tr

tr

td height=40 bgColor=#fffbec 会员ID/td

tdinput type="text" name="username" id="username"//td

/tr

tr

td height=40 bgColor=#fffbec密码/td

tdinput type="password" name="password" id="password"//td

/tr

tr

td height=40 bgColor=#fffbec确认密码/td

td

input type="password" name="realpass" id="realpass"/

/td

/tr

tr

td height=40 bgColor=#fffbecEMAIL/td

tdinput type="text" name="email" id="email"/

/tr

tr

td height=40 bgColor=#fffbec/td

tdinput type="submit" name="submit" value="注册"/input type="reset" value="重置"/td

/tr

/table

/form

/body

主页显示:index.php

?php

include("conn.php");

function cutstr($str,$cutleng)

{

$str = $str; //要截取的字符串

$cutleng = $cutleng; //要截取的长度

$strleng = strlen($str); //字符串长度

if($cutleng$strleng)return $str;//字符串长度小于规定字数时,返回字符串本身

$notchinanum = 0; //初始不是汉字的字符数

for($i=0;$i$cutleng;$i++)

{

if(ord(substr($str,$i,1))=128)

{

$notchinanum++;

}

}

if(($cutleng%2==1)($notchinanum%2==0)) //如果要截取奇数个字符,所要截取长度范围内的字符必须含奇数个非汉字,否则截取的长度加一

{

$cutleng++;

}

if(($cutleng%2==0)($notchinanum%2==1)) //如果要截取偶数个字符,所要截取长度范围内的字符必须含偶数个非汉字,否则截取的长度加一

{

$cutleng++;

}

return substr($str,0,$cutleng);

}

?

html

head

script type="text/javascript"

function All(e, itemName)

{

var aa = document.getElementsByName(itemName);

for (var i=0; iaa.length; i++)

aa[i].checked = e.checked; //得到那个总控的复选框的选中状态

}

function Item(e, allName)

{

var all = document.getElementsByName(allName)[0];

if(!e.checked) all.checked = false;

else

{

var aa = document.getElementsByName(e.name);

for (var i=0; iaa.length; i++)

if(!aa[i].checked) return;

all.checked = true;

}

}

/script

/head

?php

include("conn.php");

if(isset($_POST['del']))

{

$mm = $_POST["selected"];

$id =implode(",",$mm);

$sql = "delete from forums where id in(".$id.")";

//echo $sql;

$result=mysql_query($sql);

echo $result?"删除成功":"删除失败";

}

?

table style="BORDER-BOTTOM-WIDTH: 1px; BORDER-COLLAPSE: collapse" cellSpacing=0 cellPadding=0 width=600 align=center border=1 bordercolor=#ddddff

tr align=middle

td height=40 bgColor=#DFFFDF colspan=3论坛列表/td

/tr

tr

td colspan=3a href="login.php" style="float:right"[退出系统]/aa href="add_forum.php" style="float:right"[添加论坛]/a/td

td/td

/tr

tr align=middle

td height=40 bgColor=#DFFFDF width=80状态/td

td height=40 bgColor=#DFFFDF论坛/td

td height=40 bgColor=#DFFFDF最后更新/td

/tr

?php

$sql="select * from forums";

$result=mysql_query($sql);

$num=mysql_num_rows($result);

if($num0)

{

while($row=mysql_fetch_array($result)){

?

tr align=middle

td bgColor=#fffbecinput type="checkbox" name="selected" value="1"//td

td height=50 bgColor=#fffbec width=300

?php

echo "diva href=\"forums.php?F=".$row['ID']."\"".$row['forum_name']."/a/div";

echo cutstr($row['forum_description'],24);//最多显示24个字节,12个字,多余部分用省略号代替

echo "……";

?

/td

td height=50 bgColor=#fffbecdiv?php echo $row['last_post_time']."by".$row['last_post_author']?/div/td

/tr

?php

}

}

else

{

echo "tr bgColor=#fffbectd colspan=3对不起,论坛尚在创建中……/td/tr";

}

?

tr

td colspan=3    input type="checkbox" name="selected" value="1" onclick="All(this,'selected')"/全选/不全选/td

/tr

tr

tdinput type="button" name="del" id="del" value="删除选中项"/

?php

?

/td

/tr

/table

/html

自己创建数据库就好。

求用PHP写一个简单基本的留言板代码,有点急

数据库的创建

CREATE DATABASE GBOOK;

CREATE TABLE `gbook` (

`id` INT( 255 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,

`name` VARCHAR( 10 ) NOT NULL ,

`sex` TINYINT( 1 ) UNSIGNED NOT NULL ,

`email` VARCHAR( 255 ) NOT NULL ,

`info` TEXT NOT NULL ,

`ip` VARCHAR( 15 ) NOT NULL ,

`time_at` DATETIME NOT NULL

)

主要页面有:

input.html为初始页

insert.php为把输入内容送入数据库

show.php显示留言板内容

change.php修改留言板内容的界面

del.php删除留言板内容

change_ok.php修改留言板内容并送入数据库

input.html

html

head

meta http-equiv="content-type" content="text/html; charset=GB2312" /

title留言版/title

/head

body

form name="form1" method="post" action="insert.php"

p你的名字:input type="text" name="name" size="20" //p

p你的性别:input type="radio" value="1" name="sex" checked="checked" /男生 input type="radio" value="0" name="sex" /女生 /p

p你的E-mail:input type="text" name="email" size="20" //p

p你的留言内容:/p

ptextarea rows="9" name="info" cols="35"/textarea/p

pinput type="submit" value="提交" name="B1" /input type="reset" value="重设" name="B2" //p

/form

/body

/html

insert.php

?php

$mysql_server_name = "localhost";

$mysql_username = "root";

$mysql_password = "123456";

$mysql_database = "gbook";

$ip = getenv('REMOTE_ADDR');

$conn = mysql_connect("localhost","root","123456");

mysql_select_db("gbook");

$sql = "INSERT INTO `gbook` ( `id` , `name` , `sex` , `email` , `info` , `ip` , `time_at` )

VALUES (NULL , '$name', '$sex', '$email', '$info', '$ip', NOW( ))";

$result = mysql_query($sql,$conn);

$id = mysql_insert_id();

mysql_close($conn);

?

p留言成功/p

pa href="show.php"去留言页 /a/p

show.php

?

$mysql_server_name = "localhost";

$mysql_username = "root";

$mysql_password = "123456";

$mysql_database = "gbook";

$sql = "SELECT * FROM gbook ORDER BY 'id' DESC"; //排序 后留言的在前面显示

$conn = mysql_connect($mysql_server_name,$mysql_username,$mysql_password);

mysql_select_db($mysql_database,$conn);

$result = mysql_query($sql);

while($row = mysql_fetch_row($result))

{ // ----if语句判断男女------

if($row[2]==1)

{ $gender = '男';}

else

{ $gender = '女'; }

?

table width="752" border="1"

tr

td height="32"p?=$row[6]? ?=$row[5]? /p

p?=$row[1]?(?=$gender?) ?=$row[3]?/p/td

/tr

tr

td height="45"?=nl2br($row[4])?pa href="change.php?id=?=$row[0]?"[修改]/a a href="del.php?id=?=$row[0]?"[删除]/a/p/td

/tr

/table

hr /

?

}

mysql_free_result($result);

?

change.php

?

$mysql_server_name = "localhost";

$mysql_username = "root";

$mysql_password = "123456";

$mysql_database = "gbook";

$sql = "SELECT name, sex, email, info FROM gbook WHERE id = '$id' ";

$conn = mysql_connect($mysql_server_name,$mysql_username,$mysql_password);

mysql_select_db($mysql_database,$conn);

$result = mysql_query($sql);

$row = mysql_fetch_row($result);

?

html

head

meta http-equiv="content-type" content="text/html; charset=GB2312" /

title留言版/title

/head

body

form name="form1" method="post" action="change_ok.php?id?=$id?"

p你的名字:input type="text" name="name" size="20" value="?=$row[0]?"//p

?

// -----if语句判断男女 1为男 0为女-------

if($row[1]==1)

echo ' p你的性别:input type="radio" value="1" name="sex" checked="checked" /男 input type="radio" value="0" name="sex" /女 /p';

else

echo ' p你的性别:input type="radio" value="1" name="sex" /男 input type="radio" value="0" name="sex" checked="checked" /女 /p';

?

p你的E-mail:input type="text" name="email" size="20" value="?=$row[2]?"//p

p你的留言内容:/p

ptextarea rows="9" name="info" cols="35"?=$row[3]?/textarea/p

pinput type="submit" value="提交" /input type="reset" value="重设" //p

/form

/body

/html

del.php

?

$mysql_server_name = "localhost";

$mysql_username = "root";

$mysql_password = "123456";

$mysql_database = "gbook";

$sql = "DELETE FROM gbook WHERE id = '$id' ";

$conn = mysql_connect($mysql_server_name,$mysql_username,$mysql_password);

mysql_select_db($mysql_database,$conn);

$result = mysql_query($sql);

mysql_close($conn);

?

pa href="show.php"[返回]/a/p

change_ok.php

?

$mysql_server_name = "localhost";

$mysql_username = "root";

$mysql_password = "123456";

$mysql_database = "gbook";

$sql = "UPDATE `gbook` SET `name` = '$name',`sex` = '$sex',`email` = '$email',`info` = '$info' WHERE `id` ='$id' ";

$conn = mysql_connect($mysql_server_name,$mysql_username,$mysql_password);

mysql_select_db($mysql_database,$conn);

$result = mysql_query($sql);

mysql_close($conn);

?

pa href="show.php"[返回]/a/p

请问前辈们我想实现一个PHP留言板,页面不用刷新就能显示提交的内容!

前端页面中加jquery(JavaScript)代码:

function btn_click(){

    var url = 'php_ajax_example.php';

    var comment = '这是你的评论内容';//你自己看怎么获取它,

    //例如你把评论放在textarea id="comment"/textarea中,

    //var comment = $.trim($("#comment").html());

    var userid = 123;//评论者的id(如果要求已登录)

    var username = 'jack';//评论者名字

    var email = '123@email.com';

    $.post(url,

        {comment:comment,id:userid,name:username,email:email},

        function(back_data){

            alert(back_data);

        });

}

button onclick="btn_click();"提交评论/button

新建一个文件:php_ajax_example.php,代码:

?php

var comment = $_POST['comment'];

var userid = $_POST['id'];

//......补上你需要的数据

//把以上数据存入数据库

echo '评论保存成功!';

?

求教怎么用PHP做个留言板。

一个html表单,包含留言信息,提交给一个php文件,然后php把数据存入相应数据库。

查看留言则是php从数据库读出相应数据,然后显示给用户。

急求一个PHP的简单的留言板,输入临时名字 然后输入留言提交就可以显示在页面的

?php

include 'conn.php';

$action = $_GET['action'];

$user=str_replace(" ","",$_POST[textfield]);

if($_POST['Submit2']){

if(!empty($_POST[textfield])){

$user=str_replace(" ","",$_POST[textfield]);

$password=str_replace(" ","",$_POST[textfield2]);

$user1=md5($user);

$password1=md5($password);

function userlogin($user1)

{

global $manager;

$sql="select * from $manager where user='$user1';";

//$sql="insert into manager (user,password) values ('$user','$password');";//用于插入需要的管理员用户信息

$query=mysql_query($sql);

$row=mysql_fetch_array($query);

return $row;

}

$row=userlogin($user1);

if($row){

$ps=$password1==$row[password];

}else{

$ps=FALSE;

// echo "script type=\"text/javascript\"alert(\"用户名错误\")/script";

}

if($ps){

$_SESSION[uid]=$user;

$_SESSION[upass]=$row[password];

header("Location:index.html");

}else{

$b=FALSE;

echo "script type=\"text/javascript\"alert(\"用户名或者密码错误\")/script";

echo 'script language="JavaScript"window.location.href="login.html";/script';

}

}else{

echo "script type=\"text/javascript\"alert(\"用户名不能为空格\")/script";

echo 'script language="JavaScript"window.location.href="login.html";/script';

}

}

?

以上是userlogin.php文件,其中引用的conn.php文件代码如下:

其中数据库自己建一个,注册页面大体也相同,你理解了这个,就自己能写注册页面了

?php

@header('Content-Type: text/html; charset=utf-8');

@session_start();

$conn = @ mysql_connect("127.0.0.1", "zznt", "19880210") or die("数据库连接错误");

mysql_select_db("zznt", $conn);

//mysql_query("set NAMES 'utf8'");

//mysql_query("set character_set_client=utf8");

//mysql_query("set character_set_results=utf8");

mysql_query("set NAMES 'utf8'");

mysql_query("set character_set_client=utf8");

mysql_query("set character_set_results=utf8");

//$content=str_replace("'","钬?,$content);

//htmlspecialchars();

?

用PHP做留言板

说了的啊,就让你编写三个文件

post.php 文件

index.html 文件

display.inc文件

就是把上面的代码分别复制到记事本中在按上面的文件名保存

在放到你的网站目录下就可以了