资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

php提交留言到数据库,php提交留言到数据库里

php表单提交内容到数据库

我来给你代码:

从策划到设计制作,每一步都追求做到细腻,制作可持续发展的企业网站。为客户提供成都网站建设、网站设计、网站策划、网页设计、国际域名空间、虚拟主机、网络营销、VI设计、 网站改版、漏洞修补等服务。为客户提供更好的一站式互联网解决方案,以客户的口碑塑造优易品牌,携手广大客户,共同发展进步。

?php

$hostName = 'yourhost';

$userName = 'yourusername';

$passWords = 'yourpwd';

$conn = mysql_conn($hostName,$userName,$passWords);

if(!$conn){

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

}

$mysql_select_db('admin',$conn);

$sql="INSERT INTO user_zy (username, name, time,place,type,http,password)

VALUES

('$_POST[username]','$_POST[name]','$_POST[time]','$_POST[place]','$_POST[type]',

'$_POST[http]','$_POST[password]')";

mysql_query($sql,$conn);   //这里是添加数据。

//读取数据

$sql = "select * form user_zy where 1";   //读取所有。

$sql = "select * form user_zy where id=".$id;   //读取某一项。

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

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

$arr[] = $info; //$arr 为最后所要读取的值。

}

可以用var_dump($arr)打印出来看看。

有什么不明白可以留言。

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+mysql留言板为何提交不到数据库或者说根本就无法提交吧

嗯 $_POST['content'] 反正都要大写POST 里面的值加 引号。 下次你调试的时候 echo 下结果就明白了 比如 $_post['submit'] 你要看下有没有获取到 出问题了肯定是没获取到,所以不执行下面的命令。

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

工具:

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数据库操作主要分为5个步骤:1连接MYSQL

2连接到你的数据库

3写SQL语句

4运行sql语句

5关闭数据库

//第一步

$con

=

mysql_connect("localhost","root","123456789");

//第二步

mysql_select_db('rankingme',$conn);

//第三步

$sql="insert

into

lili

(name,sex,et,hobby,photo,tel,address,content,time)

values

($name,$sex,$et,$hobby,$photo,$tel,$address,$content,$time)"

//第四步

mysql_query($sql);

//第五步

mysql_close($con);


分享文章:php提交留言到数据库,php提交留言到数据库里
当前地址:http://cdkjz.cn/article/pheccj.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220