drccfl9407
2018-02-08 23:35
浏览 135
已采纳

通过Ajax表单提交,通过在DB中用逗号分隔的一行中插入多个选项,但是内容给出错误

I have a Ajax form that is submitting data into my MySQL database.

I have select2 boxes that allow users to select multiple choices.

Here is an example of one box's HTLM code:

<select class="select3 form-control select2-multiple track" name="sellingmethods" id ="sellingmethods" multiple="multiple" multiple data-placeholder="Choose ...">
    <option value="Telesales">Telesales</option>
    <option value="Party Planning">Party Planning</option>
    <option value="Door to Door">Door to Door</option>
    <option value="Face to Face">Face to Face</option>
    <option value="Online Demos">Online Demos</option>
    <option value="Affiliate Link">Affiliate Link</option>
    <option value="Appointment Setting">Appointment Setting</option>
</select>

When I click submit it passes the data like this :

Example Ajax Post Data

As you can see it posts the same id of the box multiple times example seen on selling methods.

At the moment my PHP code that puts it in the DB is only putting the last item into the database.

Is there a way to put the multiple selections in separated by a comma? For example "door to door,telesales".

Here is my current PHP code :

'sellingmethods' => implode(',', $this->input->post('sellingmethods')),
'sellertype' => implode(',', $this->input->post('sellertype')),
'want2sell' => implode(',', $this->input->post('want2sell')),
'productssold' => implode(',', $this->input->post('productssold')),
'industriesrepresented' => implode(',', $this->input->post('industriesrepresented')),

Which is currently giving me the error :

implode(): Invalid arguments passed

图片转代码服务由CSDN问答提供 功能建议

我有一个Ajax表单,它将数据提交到我的MySQL数据库。

我有选择2个框,允许用户选择多个选项。

以下是一个框 HTLM 代码的示例: < pre> &lt; select class =“select3 form-control select2-multiple track”name =“sellingmethods”id =“sellingmethods”multiple =“multiple”multiple data-placeholder =“Choose ...”&gt; &lt; option value =“Telesales”&gt; Telesales&lt; / option&gt; &lt; option value =“Party Planning”&gt; Party Planning&lt; / option&gt; &lt; option value =“Door to Door”&gt; Door to 门&lt; /选项&gt; &lt;选项值=“面对面”&gt;面对面&lt; /选项&gt; &lt;选项值=“在线演示”&gt;在线演示&lt; / option&gt; &lt;选项 value =“Affiliate Link”&gt; Affiliate Link&lt; / option&gt; &lt; option value =“约会设置”&gt;约会设置&lt; / option&gt; &lt; / select&gt; \ n

点击提交时 它传递的数据如下:

正如您所看到它发布相同的ID 在销售方法上看到的多次示例框。

目前,我将其放入数据库的PHP代码只是将最后一项放入数据库。

有没有办法用逗号分隔多个选项? 例如“门到门,电话销售”。

这是我当前的PHP代码:

 'sellingmethods'=&gt;  implode(',',$ this-&gt; input-&gt; post('sellingmethods')),
'sellertype'=&gt;  implode(',',$ this-&gt; input-&gt; post('sellertype')),
'want2sell'=&gt;  implode(',',$ this-&gt; input-&gt; post('want2sell')),
'productssold'=&gt;  implode(',',$ this-&gt; input-&gt; post('productssold')),
'industriesrepresented'=&gt;  implode(',',$ this-&gt; input-&gt; post('industriesrepresented')),
   
 
 

目前正在给我错误:

implode():传递的参数无效

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题