php写入数据库,php 如何把一条sql语句写入数据库
大家好,今天小编来为大家解答php写入数据库这个问题,php 如何把一条sql语句写入数据库很多人还不知道,现在让我们一起来看看吧!
php 接收到之后post数据写入数据库
form表单demo:task.html
<fieldset id="setFiled">
<legend>发布任务</legend>
<form action="registr.php" method="post" id="steForm">
<label>任务类型:</label><br>
<input type="text" name="type" id="taskType" placeholder="请选择任务类型"/><br>
<label>酬 金:</label><br>
<input type="number" name="money" id="forMoney" min="1" max="1000"/><label>元</label><br>
<label>截止时间:</label><br>
<input type="datetime" name="time" id="timeSubmit"/><span data-year="" data-month="" data-date="" id="showDate"></span><br>
<label>详细描述:</label><br>
<textarea maxlength="512" name="textAray" id="msgArea"></textarea><br>
<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中怎么循环插入数据库
一、loop写法
php模板循环中,最常见的循环就是foreach了,简单高效使php程序里大量运用了foreach,这里我们就模板里的循环进行解说。在php模板中,循环被改装成对称的loop和/loop模式,代码:
<!-- loop from=$rslist key=$key value=$value [id=rslist_id]-->
...
<!--/loop-->
参数解析:
from,数据来源
key,给数组下标附一个变量
value,值
id,给数组from里信息增加属性,这里提供了三个属性
num,当前数量,从1开始计起
index,当前索引,从0开始计起
total,当前数组数量
示例1:在文章列表中常用到的循环
<!-- loop from=$rslist key=$key value=$value-->
<li><a rel="external nofollow" rel="external nofollow" rel="external nofollow" href="{$value.url}" title="{$value.title}"><span class="date">{func date Y-m-d$value.dateline}</span>{$value.title}</a></li>
<!--/loop-->
示例2、在导航菜单中常用到的循环(这里用到了id里的num和total属性
<!-- php:$list= phpok("menu")-->(获取后台数据调用中心参数menu的数据)
<!-- loop from=$list key=$key value=$value id=list_id-->
<li{if$list_id.num== 1} class="selected"{/if}>
<a rel="external nofollow" rel="external nofollow" rel="external nofollow" href="{$value.url}" title="{$value.title}" target="{$value.target}" class='alink'>{$value.title}</a>{if$list_id.num!=$list_id.total}|{/if}</li>
<!--/loop-->
二、foreach写法
其实在phpok模板中,仍然支持旧版的循环写法,甚至支持php写法,功能和上述loop是一样的,不过没有id属性
<!--$rslist AS$key=>$value-->
<li><a rel="external nofollow" rel="external nofollow" rel="external nofollow" href="{$value.url}" title="{$value.title}">{$value.title}</a></li>
<!-- end-->
或者如下编写:
<!--$rslist AS$key=>$value-->
<li><a rel="external nofollow" href="{:$value[url]}" title="{:$value[title]}">{:$value[title]}</a></li>
<!-- end-->
怎么用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('Couldnotconnect:'.mysql_error());
}
mysql_select_db("my_db",$con);
mysql_query("INSERTINTOPersons(FirstName,LastName,Age)
VALUES('Peter','Griffin','35')");
mysql_query("INSERTINTOPersons(FirstName,LastName,Age)
VALUES('Glenn','Quagmire','33')");
mysql_close($con);
?>
(2)其次创建一个 HTML表单,这个表单可把新记录插入"Persons"表。
<html>
<body>
<formaction="insert.php"method="post">
Firstname:<inputtype="text"name="firstname"/>
Lastname:<inputtype="text"name="lastname"/>
Age:<inputtype="text"name="age"/>
<inputtype="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('Couldnotconnect:'.mysql_error());
}
mysql_select_db("my_db",$con);
$sql="INSERTINTOPersons(FirstName,LastName,Age)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";
if(!mysql_query($sql,$con))
{
die('Error:'.mysql_error());
}
echo"1recordadded";
mysql_close($con)
?>
php 如何把一条sql语句写入数据库
你提的问题简直是模棱两可的
1、你是要将sql语句写入数据库,那么你就insert插这条语句到指定的字段。
2、你是要将sql语句查询出来的结果写入数据库,那么就将得到的结果insert插入。
3、你是不知道怎么查询数据库结果,那么我告诉你应该是select* from tabname
你这问题实在是太深奥了,深奥了,奥了,了。
关于php写入数据库到此分享完毕,希望能帮助到您。