【问题标题】:mysql : how to submit 2 sets of checkbox in two different column in a tablemysql:如何在表的两个不同列中提交 2 组复选框
【发布时间】:2014-02-03 00:42:38
【问题描述】:

我有两组具有不同复选框选项的 div:

<div id="mobile_device" style="display:none;">
<font size="3"><b>Select the accessories :</b></font>
</br></br>
    <input type="checkbox" name="mobile[]" value="charger"/>  Charger &nbsp;&nbsp; &nbsp; <input type="checkbox" name="mobile[]" value="case"/> Case &nbsp;&nbsp;&nbsp;
    <input type="checkbox" name="mobile[]" value="headset"/> Headset &nbsp;&nbsp; &nbsp; <input type="checkbox" name="mobile[]" value="box"/> Box&nbsp;&nbsp; &nbsp; 
    <input type="checkbox" name="mobile[]" value="usb"/> USB Cable &nbsp;&nbsp; &nbsp; <input type="checkbox" name="mobile[]" value="sim"/> SIM<br/>
</div>

div id="desktop_device" style="display:none;">
<font size="3"><b>Select the accessories :</b></font>
</br></br>
<input type="checkbox" name="desktop[]" value="adaptor"/>  Adaptor &nbsp;&nbsp; &nbsp; <input type="checkbox" name="desktop[]" value="privacy"/> Privacy Screen &nbsp;&nbsp;&nbsp;
<input type="checkbox" name="desktop[]" value="mouse"/> Mouse &nbsp;&nbsp; &nbsp; <input type="checkbox" name="desktop[]" value="keyboard"/> Keyboard&nbsp;&nbsp; &nbsp; 
<input type="checkbox" name="desktop[]" value="connector"/> Desktop Connector <br/><br/>
</div>

现在我试图在我的数据库的两列中提交一组复选框值。

if (isset($_POST['submit']))
    { 
        // get form data, making sure it is valid
        $type = $_POST['type'];
        $name = $_POST['name'];
        $serial = $_POST['serial'];
        $imei = $_POST['imei'];
        $mobile = implode(",", $_POST['mobile']);
        $desktop = implode(",", $_POST['desktop']);
        $chargerno = $_POST['chargerno'];
        $connectorno = $_POST['connectorno'];
        $monitor = $_POST['monitor'];
        $monitorno = $_POST['monitorno'];       



            // save the data to the database
            $sql3= "INSERT INTO devices (type, name, serial, imei, mobile, desktop, chargerno, connectorno, monitor, monitorno) VALUES ('$type', '$name', '$serial', '$imei', '$mobile', $desktop, $chargerno, $connectorno, $monitor, $monitorno)";
            mysqli_query($mysqli,$sql3) or die(mysqli_error($mysqli));
            }   

但我在“字段列表”中收到类似“未知列”“适配器”的错误。

如何将两个 div 中选定的复选框值提交到两个不同的列中。

【问题讨论】:

  • 你想将它们存储为字符串?

标签: php html mysql checkbox


【解决方案1】:

$desktop 必须作为字符串传递,因此:

$sql3= "INSERT INTO devices (type, name, serial, imei, mobile, desktop, chargerno, connectorno, monitor, monitorno) VALUES ('$type', '$name', '$serial', '$imei', '$mobile', '$desktop', $chargerno, $connectorno, $monitor, $monitorno)";

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-22
    • 1970-01-01
    • 2021-04-08
    • 2018-07-29
    • 1970-01-01
    • 2019-02-02
    • 1970-01-01
    • 2019-08-22
    相关资源
    最近更新 更多