资讯

精准传达 • 有效沟通

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

php写入数据库实体,php导入数据库

php 写入数据库 例子

?php

创新互联公司是一家专注于成都网站建设、做网站与策划设计,酒泉网站建设哪家好?创新互联公司做网站,专注于网站建设10多年,网设计领域的专业建站公司;建站业务涵盖:酒泉等地区。酒泉做网站价格咨询:18980820575

// 以 MySQL 为例:

mysql_connect('127.0.0.1', 'root', 'root', 3306);  // 连接数据库

mysql_select_db('test');                           // 选择数据库

mysql_query('set names utf8');                     // 执行SQL

// 插入数据语句

$sql = "INSERT INTO table (username, password) VALUES ('Jack@163.com', '123456')";

$r = mysql_query($sql);

if (mysql_affected_rows()) {

echo '新增成功';

} else {

echo mysql_error();

}

php文件中将数据写入数据库

"是不是把数据库建好然后导出.sql文件放在默认的根目录D:/www文件夹中?然后在php文件中直接用啊",你这么说,你是不是没学过php?什么专业的。$db=new mysqli('localhost','root','root','users') 中,mysqli是一个类。你需要检查一下这个类有没有问题。有没有什么错误提示呢??(谢谢采纳)

php 接收到之后post数据写入数据库

form表单demo:task.html

fieldset id="setFiled"

legend发布任务/legend

form action="registr.php" method="post" id="steForm"

label任务类型:/labelbr

input type="text" name="type"  id="taskType" placeholder="请选择任务类型"/br

label酬nbsp;nbsp;金:/labelbr

input type="number" name="money" id="forMoney" min="1" max="1000"/label元/labelbr

label截止时间:/labelbr

input type="datetime" name="time" id="timeSubmit"/span data-year="" data-month="" data-date="" id="showDate"/spanbr

label详细描述:/labelbr

textarea maxlength="512" name="textAray" id="msgArea"/textareabr

input type="submit" name="subMit" id="forSub" value="点击发布" /

/form

扩展资料

php接收POST数据的三种方式

1、$_POST 方式接受数据

$_POST 方式是由通过HTTP的POST方法传递过来的数据组成的数组,是一个自动全局变量。

注:只能接收Content-Type:application/x-www-form-urlencode提交的数据。也就是只能接收表单过来的数据。

2、GLOBLES[‘HTTP_RAW_POST_DATA’]

如果访问原始POST数据不是php能够识别的文档类型,比如:text/xml 或者soap等等,可以用$GLOBLES[‘HTTP_RAW_POST_DATA’]来接收,$HTTP_RAW_POST_DATA变量包含有原始POST数据。此变量仅在碰到未识别的MIME数据时产生。

注:$HTTP_RAW_POST_DATA对于enctype=”multipart/form-data”表单数据不可用,也就是说使用$HTTP_RAW_POST_DATA无法接受网页表单post过来的数据。

3、file_get_contents(“php://input”);

如果访问原始POST数据,更好的方法是使用file_get_content(“php://input”);对于未指定Content-Type的POST数据,可以使用该方法读取POST原始数据,包括二进制流也可以和$HTTP_RAW_POST_DATA比起来。它带来的生存眼里更小,并且不需要任何特殊的php.ini设置。

注:php://input不能用于 enctype=”multipart/form-data”

例如:$postStr = file_get_contents("php://input"); //获取POST数据

怎么用php把html表单内容写入数据库

1:首先要使用PHP的超全局变量 $_GET 和 $_POST 用于收集表单数据(form-data)

2:然后使用INSERT INTO 语句用于向数据库表中插入新记录。

具体示例:

(1)首先创建了一个名为 "Persons" 的表,有三个列:"Firstname", "Lastname" 以及 "Age"。

?php

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

if (!$con)

{

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

}

mysql_select_db("my_db", $con);

mysql_query("INSERT INTO Persons (FirstName, LastName, Age) 

VALUES ('Peter', 'Griffin', '35')");

mysql_query("INSERT INTO Persons (FirstName, LastName, Age) 

VALUES ('Glenn', 'Quagmire', '33')");

mysql_close($con);

?

(2)其次创建一个 HTML 表单,这个表单可把新记录插入 "Persons" 表。

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

(3)接着当用户点击上例中 HTML 表单中的提交按钮时,表单数据被发送到 "insert.php"。"insert.php" 文件连接数据库,并通过

$_POST 变量从表单取回值。然后,mysql_query() 函数执行 INSERT INTO 语句,一条新的记录会添加到数据库表中。

?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如何写入数据库

数组吧,直接把数组转字符串啊

implode() 函数返回由数组元素组合成的字符串。(适合一维数组)

$arr = array('Hello', 'World', 'I', 'love', 'Shanghai');

1 echo implode(" ",$arr);//加空格

the result : Hello World I love Shanghai

2 echo implode(",",$arr);//加逗号

the result : Hello,World,I,love,Shanghai

转换数组为字符串后插入数据库就可以了。


当前题目:php写入数据库实体,php导入数据库
文章起源:http://cdkjz.cn/article/hoejho.html
多年建站经验

多一份参考,总有益处

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

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

大客户专线   成都:13518219792   座机:028-86922220