php - 使用 implode 函数在表格的一列中插入多个复选框

标签 php database checkbox implode

我的代码中有这个复选框

<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']);

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

最佳答案

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

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

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

关于php - 使用 implode 函数在表格的一列中插入多个复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31987587/

相关文章:

php - 为什么我有这个laravel错误?

php - 如何从数据库中选择数据并将其用作下一页中的变量?

php - 禁用 iframe 的基本身份验证

java - 用于填充多个表的复选框和 sql 命令的对象名称

php - 在phpexcel中合并后按行和列设置单元格值的问题

java - Tokyo Cabinet - 内存调整

php - 将具有图像尺寸的记录更新到数据库。我想等不到10小时

ruby - 电话在数据库架构中定义为字符串,但整数在 Ruby 中保存为有效

php - 为多个复选框子组设置默认值

html - css自定义复选框布局