使用 implode 函数在 table 的一列中插入多个复选框

insert multiple checkboxes in one column of a table using implode function

我的代码中有这个复选框

<fieldset><legend>What search engine do you prefer?</legend><br><br><br>
        <!-- container ko start -->
        <div id="container2">

            <table>
                <tr>
                    <td width="30%">
                        <label><img src="images/google.png" height="40px" width="120px"></label>
                        <input type="checkbox" name="engine1[]" value="google">
                    </td>
                    <td width="30%">
                        <label><img src="images/yahoo.png" height="40px" width="120px"></label>
                        <input type="checkbox" name="engine1[]"  value="yahoo">
                    </td>
                    <td width="30%">
                        <label><img src="images/bing.png" height="40px" width="120px"></label>
                        <input type="checkbox" name="engine1[]" value="bing">
                    </td>
                </tr>

            </table>

        </div>
    </fieldset>


    <br><br><br><br><br>
    <fieldset><legend>Put check on the icons that you are familiar with.</legend><br><br><br>

        <div id="container2">

            <table>

                <tr>
                    <td>
                        <label><img src="images/fb.png" height="40px" width="40px"></label>
                        <input type="checkbox" name="engine2[]" value="fb">
                    </td>
                    <td>
                        <label><img src="images/twit.png" height="40px" width="40px"></label>
                        <input type="checkbox" name="engine2[]" value="twitter">
                    </td>
                    <td>
                        <label><img src="images/googplus.png" height="40px" width="40px"></label>
                        <input type="checkbox" name="engine2[]" value="googleplus">
                    </td>
                </tr>


                <tr>
                    <td>
                        <label><img src="images/link.png" height="40px" width="40px"></label>
                        <input type="checkbox" name="engine2[]" value="linkedin">
                    </td>
                    <td>
                        <label><img src="images/pin.png" height="40px" width="40px"></label>
                        <input type="checkbox" name="engine2[]" value="pinterest">
                    </td>
                    <td>
                        <label><img src="images/del.png" height="40px" width="40px"></label>
                        <input type="checkbox" name="engine2[]" value="delicious">
                    </td>
                </tr>


                <tr>
                    <td>
                        <label><img src="images/stumb.png" height="40px" width="55px"></label>
                        <input type="checkbox" name="engine2[]" value="stumbleupon">
                    </td>
                    <td>
                        <label><img src="images/diig.png" height="40px" width="40px"></label>
                        <input type="checkbox" name="engine2[]" value="diigo">
                    </td>
                </tr>


            </table>


        </div>
        <!-- container ko end -->
    </fieldset>

两组,分别是engine1和engine2。我想用这段代码使用 implode 将它们插入我的数据库中..

$_POST['engine1'] = array();
    $_POST['engine2'] = array();

    $engine1 = implode(',', $_POST['engine1']);
    $engine2 = implode(',', $_POST['engine2']);

但每次我检查我的数据库时 table,列都是空的。 你认为我做错了什么??请帮助!

您将 $_POST['engine1'] 声明为一个空数组,如果它存在则覆盖它。删除以下行:

$_POST['engine1'] = array();
$_POST['engine2'] = array();

因此 $_POST['engine1'] 来自 POSTED 表单值。

删除这些行:

$_POST['engine1'] = array();
$_POST['engine2'] = array();

仅使用:

$engine1 = implode(',', $_POST['engine1']);
$engine2 = implode(',', $_POST['engine2']);