资讯

精准传达 • 有效沟通

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

数据库加数据php 数据库加数据语句

PHP加数据库

把来自表单的数据插入数据库

创新互联建站服务项目包括卡若网站建设、卡若网站制作、卡若网页制作以及卡若网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,卡若网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到卡若省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!

现在,我们创建一个 HTML 表单,这个表单可把新记录插入 "Persons" 表。

这是这个 HTML 表单:

1

2

3

4

5

6

7

8

9

10

11

12

html

body

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

Firstname: input type="text" name="firstname" /

Lastname: input type="text" name="lastname" /

Age: input type="text" name="age" /

input type="submit" /

/form

/body

/html

当用户点击上例中 HTML 表单中的提交按钮时,表单数据被发送到 "insert.php"。"insert.php" 文件连接数据库,并通过 $_POST 变量从表单取回值。然后,mysql_query() 函数执行 INSERT INTO 语句,一条新的记录会添加到数据库表中。

下面是 "insert.php" 页面的代码:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

?php

$con = mysql_connect("localhost","peter","abc123");

if (!$con)

{

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

}

mysql_select_db("my_db", $con);

$sql="INSERT INTO Persons (FirstName, LastName, Age)

VALUES

('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";

if (!mysql_query($sql,$con))

{

die('Error: ' . mysql_error());

}

echo "1 record added";

mysql_close($con)

?

PHP在网站上实现跟数据库添加数据

把来自表单的数据插入数据库

现在,我们创建一个 HTML 表单,这个表单可把新记录插入 "Persons" 表。

这是这个 HTML 表单:

html

body

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

Firstname: input type="text" name="firstname" /

Lastname: input type="text" name="lastname" /

Age: input type="text" name="age" /

input type="submit" /

/form

/body

/html

当用户点击上例中 HTML 表单中的提交按钮时,表单数据被发送到 "insert.php"。"insert.php" 文件连接数据库,并通过 $_POST 变量从表单取回值。然后,mysql_query() 函数执行 INSERT INTO 语句,一条新的记录会添加到数据库表中。

下面是 "insert.php" 页面的代码:

?php

$con = mysql_connect("localhost","peter","abc123");

if (!$con)

{

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

}

mysql_select_db("my_db", $con);

$sql="INSERT INTO Persons (FirstName, LastName, Age)

VALUES

('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";

if (!mysql_query($sql,$con))

{

die('Error: ' . mysql_error());

}

echo "1 record added";

mysql_close($con)

?

用php代码怎么往数据库里自定义插入数据

现在,我们创建一个

HTML

表单,这个表单可把新记录插入

"Persons"

表。

这是这个

HTML

表单:

123456789101112

htmlbody

form

action="insert.php"

method="post"Firstname:

input

type="text"

name="firstname"

/Lastname:

input

type="text"

name="lastname"

/Age:

input

type="text"

name="age"

/input

type="submit"

//form

/body/html

当用户点击上例中

HTML

表单中的提交按钮时,表单数据被发送到

"insert.php"。"insert.php"

文件连接数据库,并通过

$_POST

变量从表单取回值。然后,mysql_query()

函数执行

INSERT

INTO

语句,一条新的记录会添加到数据库表中。


分享题目:数据库加数据php 数据库加数据语句
本文路径:http://cdkjz.cn/article/hhsgcj.html
多年建站经验

多一份参考,总有益处

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

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

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