[英]array created from foreach loop now want to insert into database
I have a form, there i have foreach loop.我有一个表格,我有 foreach 循环。 I used ajax to get data from the FORM using NAME attr for ex: price is coming from a input filed
我使用 ajax 使用 NAME attr 从表单中获取数据,例如:价格来自输入文件
$price = "price$fetch[id]";
<input type="text" id="<?php print $price;?>" name="<?php print $price;?>" value="">
This is my array这是我的数组
Array (
[price26] => 19.07
[duration26] => 30
[medic_morning26] => 1
[medic_day26] => 1
[medic_night26] => 1
[real_order_qty26] =>
[order_for_how_many_days26] =>
[total_price26] =>
[price27] => 24.22
[duration27] => 7
[medic_morning27] => 1
[medic_day27] => 0
[medic_night27] => 0
[real_order_qty27] =>
[order_for_how_many_days27] =>
[total_price27] =>
[CUSTOMERID] => 33
[prescription_code] => 0001
[DA_id] =>
[given_DA] => errr
[new_DA] =>
)
and this is my database filed这是我提交的数据库
`price` `duration` `medic_morning` `medic_day` `medic_night` `real_order_qty` `order_for_how_many_days` `total_price`
Can anyone help me , to insert the data into database?谁能帮我将数据插入数据库?
$array = array_here; //here your array...
$query = "INSERT INTO `table_name` (`price`, `duration`, `medic_morning`, `medic_day`, `medic_night`, `real_order_qty`, `order_for_how_many_days`, `total_price`) VALUES ('$array['price26']', '$array['duration26']', '$array['medic_morning26']', '$array['medic_day26']', '$array['medic_night26']', '$array['real_order_qty26']', '$array['order_for_how_many_days26']', '$array['total_price26']')";
mysqli_query($query);
my mistake: i tried to make all the input filed name unique just like ID , thats why cant manage the name ARRAY , so instead of我的错误:我试图让所有输入的文件名像 ID 一样唯一,这就是为什么不能管理名称 ARRAY ,而不是
<input name="price$fetch['id']" id="price$fetch['id']" value="" >
i used我用了
<input id="price$fetch['id']" name="price[]" value="" >
now i can handle all the price array (same for other filed..)现在我可以处理所有的价格数组(其他文件相同..)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.