php留言板数据库 php留言板数据库怎么用

php怎么在mysql创建留言板步骤

工具:

创新互联主营图们网站建设的网络公司,主营网站建设方案,app软件开发公司,图们h5小程序开发搭建,图们网站营销推广欢迎图们等地区企业咨询

Dreamweaver

php、mysql服务器

步骤/方法

首先是确定自己的留言板需求.例如:名字,邮件及留言内容.

一. 建立一个数据库guestbook。

CREATE TABLE IF NOT EXISTS `content` (

`id` int(11) NOT NULL auto_increment,

`name` varchar(20) NOT NULL,

`email` varchar(50) NOT NULL,

`content` varchar(200) NOT NULL,

PRIMARY KEY (`id`))

ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=3;

二. 新建config.php

? php

$q = mysql_connect("服务器","数据库用户","数据库密码");

if(!$q)

{

die('Could not connect: ' . mysql_error());

}

mysql_query("set names utf8"); //以utf8读取数据

mysql_select_db("guestbook",$q); //数据库

?

三. 新建index.php

?php

include("config.php"); //引入数据库连接文件

$sql = "select * from content"; //搜索数据表content

$resule = mysql_query($sql,$q);

?

html

meta http-equiv="Content-Type" content="text/html; charset=utf-8" /

body

table width="678" align="center"

tr

td colspan="2" h1留言本 /h1 /td

/tr

tr

td width="586" a href="index.php"首页 /a | a href="liuyan.php"留言 /a /td

/tr

/table

p

?

while($row=mysql_fetch_array($resule))

{

?

/p

table width="678" border="1" align="center" cellpadding="1" cellspacing="1"

tr

td width="178"Name: ? echo $row[1] ? /td

td width="223"Email: ? echo $row[2] ? /td

/tr

tr

td colspan="4" ? echo $row[3] ? /td

/tr

tr

/table

?

}

?

/body

/html

四. 新建liuyan.php

html

body

meta http-equiv="Content-Type" content="text/html; charset=utf-8" /

table width="678" align="center"

tr

td colspan="2" h1留言本 /h1 /td

/tr

tr

td width="586" a href="index.php"首页 /a | a href="liuyan.php"留言 /a /td

/tr

/table

table align="center" width="678"

tr

td

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

p

Name:

input name="name" type="text" id="name"

/p

pEmail: input type="test" name="email" id="email" /p

p

留言:

/p

p

textarea name="content" id="content" cols="45" rows="5" /textarea

/p

p

input type="submit" name="button" id="button" value="提交"

input type="reset" name="button2" id="button2" value="重置"

/p

/form

/td

/tr

/table

/body

/html

五. 新建post.php

?php

header("content-Type: text/html; charset=utf-8");

include("config.php");

$name= $_POST['name'];

$email= $_POST['email'];

$patch = $_POST['content'];

$content = str_replace("

"," br /",$patch);

$sql = "insert into content (name,email,content) values ('$name','$email','$content')";

mysql_query($sql);

echo " scriptalert('提交成功!返回首页。');location.href='index.php'; /script";

?

这样已经成功的写出一个留言板了。

第二部分

此次将在上面版本上加多管理,回复等功能。

首先在sql中字节。

ALTER TABLE `content` ADD `reply` VARCHAR( 200 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL AFTER `content`

一. 新建login.php

html xmlns=""

meta http-equiv="Content-Type" content="text/html; charset=utf-8" /

title无标题文档 /title

/head

body table width="678" align="center"

tr

td colspan="2" h1留言本 /h1 /td

/tr

tr

td width="586" a href="index.php"首页 /a | a href="liuyan.php"留言 /a /td

/tr

/table

table align="center" width="678"

tr

td align="center"

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

label for="textfield" /label

p /p

p帐号:

input type="text" name="name" id="name"

/p

p密码:

input type="password" name="pw" id="pw"

/p

p

input type="submit" name="button" id="button" value="提交"

input type="reset" name="button2" id="button2" value="重置"

/p

/form /td

/tr

/table

/body

/html

二.login2.php

?

session_start();

header("content-Type: text/html; charset=utf-8");

$name = $_POST['name'];

$pw = $_POST['pw'];

if($name == "admin" $pw == "admin"){

$_SESSION["adminname"] = $name;

echo " scriptalert('登录完成,返回首页!');location.href='index.php'; /script";

}else{

echo " scriptalert('错误!');location.href='login.php'; /script";

}

?

三. 在原有的index.php上添加

?php

session_start();

include("config.php");

$sql = "select * from content";

$resule = mysql_query($sql,$q);

?

html

meta http-equiv="Content-Type" content="text/html; charset=utf-8" /

body

table width="678" align="center"

tr

td colspan="2" h1留言本 /h1 /td

/tr

tr

td width="586" a href="index.php"首页 /a | a href="liuyan.php"留言 /a /td

td width="80"

// 新增管理员登录

?php

if (isset($_SESSION['adminname']) $_SESSION["adminname"] == "admin"){

echo " a href='logout.php'登出 /a";

}else{

echo " a href='login.php'管理员登录 /a";

}

?

/td

/tr

/table

p

?

while($row=mysql_fetch_array($resule))

{

?

/p

table width="678" border="1" align="center" cellpadding="1" cellspacing="1"

tr

td width="178"Name: ? echo $row[1] ? /td

td width="223"Email: ? echo $row[2] ? /td

td width="100"

?php

if(isset($_SESSION['adminname']) $_SESSION["adminname"] == "admin"){

echo " a href='huifu.php?id=" . $row[0] . "'回复 /a";

echo " | " . " a href='delete.php?id=" . $row[0] . "'删除 /a";

} else {

echo "";

}

?

/td

/tr

tr

td colspan="4" ? echo $row[3] ? /td

/tr

tr

td colspan="4" ?

if($row[4] == ""){

?

? echo "暂无回复。";?

? }else {echo "管理员回复:". $row[4]; } ? /td

/tr

/table

?

}

?

/body

/html

四. 新建huifu.php

?php

include("config.php");

$sql = "select * from content where id=".$_GET["id"];

$resule = mysql_query($sql,$q);

SetCookie("id",$_GET["id"]);

session_start();

header("content-Type: text/html; charset=utf-8");

if(empty($_SESSION["adminname"])){

exit(" script language='javascript'alert('您尚未登录后台,或登录已超时,请重新登录!');window.location.href='login.php'; /script");

}

?

!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""

html xmlns=""

head

meta http-equiv="Content-Type" content="text/html; charset=utf-8" /

title无标题文档 /title

/head

body

table width="678" align="center"

tr

td colspan="2" h1留言本 /h1 /td

/tr

tr

td width="586" a href="index.php"首页 /a | a href="liuyan.php"留言 /a /td

/tr

/table

table align="center" width="678"

tr

td

form name="reply" method="post" action="reply.php"

p回复:

?

while($row=mysql_fetch_array($resule))

{

echo $row[3];

}

?

/p

p

textarea name="reply" id="reply" cols="45" rows="5" /textarea

/p

p

input type="submit" name="button" id="button" value="回复" /

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

/p

/form

/td

/tr

/table

/body

/html

五. reply.php 回复留言提交页面.

?

include("config.php");

$id = $_COOKIE["id"];

$sql = "select * from content";

header("content-Type: text/html; charset=utf-8");

$patch = $_POST["reply"];

$reply = str_replace("

"," br /",$patch);

$resule = mysql_query("UPDATE `2`.`content` SET `reply` = '$reply' WHERE `content`.`id` ="."$id");

echo " scriptalert('回复成功!');location.href='index.php'; /script";

?

这样就可以建立出一个简单的管理.管理帐号都是admin 因为只是判别输入的是不是admin 是的话就把值输入进session中.

php留言板,用浏览器查看不了数据库内容

程序有问题,需要对内容进行转义,特殊符号都不能直接入库的

php编写留言板传值不成功。(能连接数据库)

1.在mysql中建立一个数据库(guest),该数据库中有一个表(note),该表包含以下字段name(10),address(25),postcode(7),tel(12),email(15),note(100).类型为varchar.2.编辑好留言板界面(在此不在赘述).3.编写处理程序?phpif($name==){echo请输入您的姓名;}elseif($address==){echo请输入您的地址;}elseif($postcode==){echo请输入您的邮编;}elseif($tel==){echo请输入您的电话;}elseif($email==){echo请输入您的E_mail地址;}elseif($note==){echo请输入您的留言;}else{$link=mysql_connectlocalhost,数据库的权限用户名,数据库的权限密码);mysql_select_db(guest);$query=insertintonotevalues('$name','$address','$postcode','$tel','$email','$note');$result=mysql_query($query);echo您的留言已经成功的加入到数据库,谢谢!;}mysql_close($link);? ----------------------------------------------- 谢谢请采纳: 不能发连接啊,请在百度 搜索‘珍惜知识网’点进去就是了[WCLT]

php留言板可以把数据提交到数据库,但是读取不了数据怎么办?

1:可以新增数据的话表示数据库连接没有问题

2:请检查mysql里面

asp

表有没有数据

,有的话

code

:

$_sql

=

$conn-query("select

*

from

asp

where

1=1

order

by

date

desc

limit

0,5");

if($_sql

$_sql-num_rows0){

while($_rs

=

$_sql-fetch_array(MYSQL_ASSOC)){

echo

'内容:'.$_rs['content'];

echo

'时间:'.$_rs['date'];

//打印全部

print_r($_rs);

}else{

echo

'没有任何数据';

}

}

//分页的话建议采用分页类:

PHP留言板写完后,数据库连接正常;本地留言后数据库显示输入的内容;但是使用美国空间的数据库就无法显示

如果网页空间和数据库服务器是同在一台服务器,那数据库连接的地址应该是localhost

你弄个域名做什么呢?

如果不是同在一台服务器, 那也应该是数据库服务器所在的ip地址, 并且mysql数据库所对应的登陆用户, 须支持远程连接!

你的sql语句也不够优化,

首先, id字段, 是自增的, 1过了就2, 2过了就3, 你写入id值做什么呢?

还有,最后一个lastdate字段, 你写入的是当前时间, 那既然是当前时间, 何不直接在数据库给这个字段设置一个默认值, 值就是当前日期时间, 何必来sql语句中写入呢?

php留言板,只显示第一条留言,后面留言之后不显示,数据库也没记录。

与数据库进行交互就是了,当你留言之后,点击确定之后---向数据库添加留言信息,如果你想在留言而只想显示一条,那就验证

,查询数据库是否存在你的留言,如果存在返回你已经留过言了的信息,并且不能点击添加留言按钮就是了啊


文章名称:php留言板数据库 php留言板数据库怎么用
转载注明:http://myzitong.com/article/docshco.html