Multiple INSERT INTO MySQL from $_POST array(来自 $_POST 数组的多个 INSERT INTO MySQL)
问题描述
我从一个表单中收到以下数组:
I am receiving the following arrays from a form:
我需要构建一个如下所示的查询:
I need to build a query looking like this:
根据选中的复选框,第一个数组每次都会有所不同.
And the first array will be different every time based on the checked checkboxes.
推荐答案
好吧,您可以尝试在该数组上使用 foreach 进行循环.因此,假设您已将复选框命名为 name="checkbox[]"
.
Well, you can try looping with a foreach on that array. So let's say you have named your checkboxes as name="checkbox[]"
.
然后在您正在处理 $_POST
变量的页面上,您可以执行此操作
Then on the page where you are processing the $_POST
vars you can do
这只是一个让您入门的伪代码.
This is just a pseudo-code to get you started.
您可以在此处找到有关准备好的语句的更多信息:http:///php.net/manual/en/mysqli-stmt.bind-param.php
You can find more info on prepared statements here: http://php.net/manual/en/mysqli-stmt.bind-param.php
这篇关于来自 $_POST 数组的多个 INSERT INTO MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!