复选框的多个值插入只有最后一个值正在数据库中 [英] multiple values insertion of checkbox only last value is taking in database

查看:79
本文介绍了复选框的多个值插入只有最后一个值正在数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在复选框中插入多个值,但是现在好像只是输入的最后一个值正在插入数据库.

I need to insert more than one values in checkbox but now it is seemed to be only the last value am entering is inserting to database.

这是我的HTML代码

<input id="option5" type="checkbox" name="product[]"  value="<?php echo $result["software"];?>"> 

<label for="option5"><span><span></span></span><?php echo $result["software"];?></label>

插入代码为

$array = array($_POST['product']);            
$value = implode(',', $array);        
echo $value;

推荐答案

如果要在数据库中保存多个值,则需要在html中创建多个复选框,然后使用implode()方法保存值,如下所示:-

If you want to save multiple values in database then you need to create multiple checkboxes in html and then save the values with implode() method as below:-

<input id="option1" type="checkbox" name="product[]"  value="value1">
<label for="option1">Value1</label>
<input id="option2" type="checkbox" name="product[]"  value="value2">
<label for="option2">Value2</label>
<input id="option3" type="checkbox" name="product[]"  value="value3"> 
<label for="option3">Value3</label>

现在要存储在数据库中,可以使用implode()方法.

now to store in database you can use implode() method.

$values=implode(",",$_POST['product']);

现在将$ values存储在数据库中.

now store the $values in the database.

这篇关于复选框的多个值插入只有最后一个值正在数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆