<bdo id='SLbjT'></bdo><ul id='SLbjT'></ul>

    <i id='SLbjT'><tr id='SLbjT'><dt id='SLbjT'><q id='SLbjT'><span id='SLbjT'><b id='SLbjT'><form id='SLbjT'><ins id='SLbjT'></ins><ul id='SLbjT'></ul><sub id='SLbjT'></sub></form><legend id='SLbjT'></legend><bdo id='SLbjT'><pre id='SLbjT'><center id='SLbjT'></center></pre></bdo></b><th id='SLbjT'></th></span></q></dt></tr></i><div id='SLbjT'><tfoot id='SLbjT'></tfoot><dl id='SLbjT'><fieldset id='SLbjT'></fieldset></dl></div>
    1. <small id='SLbjT'></small><noframes id='SLbjT'>

      <tfoot id='SLbjT'></tfoot>
      <legend id='SLbjT'><style id='SLbjT'><dir id='SLbjT'><q id='SLbjT'></q></dir></style></legend>
    2. 来自 $_POST 数组的多个 INSERT INTO MySQL

      时间:2023-10-30
              <tbody id='Anm8e'></tbody>
            <i id='Anm8e'><tr id='Anm8e'><dt id='Anm8e'><q id='Anm8e'><span id='Anm8e'><b id='Anm8e'><form id='Anm8e'><ins id='Anm8e'></ins><ul id='Anm8e'></ul><sub id='Anm8e'></sub></form><legend id='Anm8e'></legend><bdo id='Anm8e'><pre id='Anm8e'><center id='Anm8e'></center></pre></bdo></b><th id='Anm8e'></th></span></q></dt></tr></i><div id='Anm8e'><tfoot id='Anm8e'></tfoot><dl id='Anm8e'><fieldset id='Anm8e'></fieldset></dl></div>

              <small id='Anm8e'></small><noframes id='Anm8e'>

              <tfoot id='Anm8e'></tfoot>

            1. <legend id='Anm8e'><style id='Anm8e'><dir id='Anm8e'><q id='Anm8e'></q></dir></style></legend>
              • <bdo id='Anm8e'></bdo><ul id='Anm8e'></ul>
                本文介绍了来自 $_POST 数组的多个 INSERT INTO MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我从一个表单中收到以下数组:

                I am receiving the following arrays from a form:

                array (size=1)
                    'checkbox' => 
                array (size=2)
                    0 => string '14' (length=2)
                    1 => string '13' (length=2)
                    2 => string '15' (length=2)
                array (size=1)
                    'id' => string '1' (length=1)
                

                我需要构建一个如下所示的查询:

                I need to build a query looking like this:

                $sql = "INSERT INTO table(column1,column2) VALUES (14,1),(13,1),(15,1)";

                根据选中的复选框,第一个数组每次都会有所不同.

                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

                $sql = "INSERT INTO table(column1,column2) VALUES (?,?)";
                $stmt = $mysqli->prepare($sql);
                foreach ($_POST['checkbox'] as $box) {
                    //process each checkbox here
                    $stmt->bind_param('ss', $box, $otherValue);
                    $stmt->execute();
                }
                

                这只是一个让您入门的伪代码.

                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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:PHP/PDO 将当前日期加一个月插入 MYSQL 下一篇:一个查询插入多行多列

                相关文章

                <legend id='QLH10'><style id='QLH10'><dir id='QLH10'><q id='QLH10'></q></dir></style></legend>
                  <i id='QLH10'><tr id='QLH10'><dt id='QLH10'><q id='QLH10'><span id='QLH10'><b id='QLH10'><form id='QLH10'><ins id='QLH10'></ins><ul id='QLH10'></ul><sub id='QLH10'></sub></form><legend id='QLH10'></legend><bdo id='QLH10'><pre id='QLH10'><center id='QLH10'></center></pre></bdo></b><th id='QLH10'></th></span></q></dt></tr></i><div id='QLH10'><tfoot id='QLH10'></tfoot><dl id='QLH10'><fieldset id='QLH10'></fieldset></dl></div>

                      <bdo id='QLH10'></bdo><ul id='QLH10'></ul>
                    <tfoot id='QLH10'></tfoot>

                    <small id='QLH10'></small><noframes id='QLH10'>