【问题标题】:insert multiple checkboxes in one column of a table using implode function使用 implode 函数在表格的一列中插入多个复选框
【发布时间】:2015-08-13 20:03:41
【问题描述】:

我的代码中有这个复选框

<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'] = array(); $_POST['engine2'] = array();

标签: php database checkbox implode


【解决方案1】:

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

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

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

【讨论】:

    【解决方案2】:

    删除这些行:

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

    只使用:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-15
      • 2012-03-20
      • 2011-09-06
      相关资源
      最近更新 更多