
HTML
表单,这个表单可把新记录插入
"Persons"
表。
这是这个
HTML
表单:
123456789101112
<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
语句,一条新的记录会添加到数据库表中。
有两种方法添加一个元素:分别是 push()和arr[]
1、Php代码
$arr = array()
array_push($arr, el1, el2 ... eln)
2、Php代码
$arr = array()
$arr[] = el1
$arr[] = el2
...
$arr[] = eln
扩展资料
对于任何的类型:整型、浮点、字符串、布尔和资源,如果将一个值转换为数组,将得到一个仅有一个元素的数组(其下标为 0),该元素即为此标量的值。
如果将一个对象转换成一个数组,所得到的数组的元素为该对象的属性(成员变量),其键名为成员变量名。
如果将一个 NULL 值转换成数组,将得到一个空数组。
PHP的特性包括:
1. PHP 独特的语法混合了 C、Java、Perl 以及 PHP 自创新的语法。
2. PHP可以比CGI或者Perl更快速的执行动态网页——动态页面方面,与其他的编程语言相比,
PHP是将程序嵌入到HTML文档中去执行,执行效率比完全生成htmL标记的CGI要高许多;
PHP具有非常强大的功能,所有的CGI的功能PHP都能实现。
3. PHP支持几乎所有流行的数据库以及 *** 作系统。
4. 最重要的是PHP可以用C、C++进行程序的扩展!
参考资料:百度百科-PHP
最近有一个需求,前端向后台提交json,后台解析并且将提交的值插入数据库中,难点
1、php解析json(这个不算难点了,网上实例一抓一大把)
2、解析json后,php怎样拿到该拿的值
<?php
require
('connect.php')
/*
本例用到的数据:
post_array={"order_id":"0022015112305010013","buyer_id":"2","seller_id":"1","all_price":"100.00","json_list":[{"product_id":"3","product_number":"3"},{"product_id":"8","product_number":"2"},{"product_id":"10","product_number":"4"}]}
*/
$post_array=$_POST['post_array']
//--解析Json,获取对应的变量值
$obj=json_decode($post_array,TRUE)
$order_id
=
$obj['order_id']
$buyer_id
=
$obj['buyer_id']
$seller_id
=
$obj['seller_id']
$all_price
=
$obj['all_price']
$i=0//循环变量
//--得到Json_list数组长度
$num=count($obj["json_list"])
//--遍历数组,将对应信息添加入数据库
for
($i$i<$num$i++)
{
$list_product_id[]=$obj["json_list"][$i]["product_id"]
$list_product_number[]=$obj["json_list"][$i]["product_number"]
$insert_order_product_sql="INSERT
INTO
tbl_order_product
(order_id,product_id,product_number)
VALUES
(?,?,?)"
$result
=
$sqlconn
->
prepare($insert_order_product_sql)
$result
->
bind_param("sss",
$order_id,$list_product_id[$i],$list_product_number[$i])
$result->execute()
}
//--添加订单信息
$insert_order_sql="INSERT
INTO
tbl_order
(order_id,buyer_id,seller_id,all_price)
VALUES
(?,?,?,?)"
$result=$sqlconn->prepare($insert_order_sql)
$result->bind_param("ssss",$order_id,$buyer_id,$seller_id,$all_price)
$result->execute()
$result
->
close()
$sqlconn
->
close()
?>
投稿者信息
昵称:
Hola
Email:
jamcistos@outlook.com
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)