$checkbox = "";
if(!empty($_POST)) {
for (!$i=0; $i<sizeof($checkbox);$i++) {
$query="INSERT INTO qe_qcc (checkbox) VALUES ('".$checkbox[$i]."')";
mysql_query($query) or die(mysql_error());
}
这是我的HTML代码
<tr>
<td><input type="checkbox" name="check1[]" value="Enhance Productivity" />Enhance Productivity</td>
<td> <input type="checkbox" name="check1[]" value="Enhance Quality" />Enhance Quality</td>
<td> <input type="checkbox" name="check1[]" value="Save Time" />Save Time</td>
<td> <input type="checkbox" name="check1[]" value="Save Materials" />Save Materials</td>
<td> <input type="checkbox" name="check1[]" value="Save Stock" />Save Stock</td>
<td> <input type="checkbox" name="check1[]" value="Increase Safety" />Increase Safety</td>
<td> <input type="checkbox" name="check1[]" value="Financial Saving" />Financial Saving</td>
<td> <input type="checkbox" name="check1[]" value="Customer Friendly" />Customer Friendly</td>
<td> <br /><br /><input type="checkbox" name="check1[]" value="Others" />Others</td>
</tr>
答案 0 :(得分:1)
首先不要使用mysql_
,它已被弃用..(在CI ..你可以很容易地改变它)
如果您使用的是codeigniter,则使用活动记录
然后第三......
<?php
if(isset($_POST))
{
foreach($_POST['check1'] as $rescheck)
{
$this->db->insert('qe_qcc', $rescheck);
}
}
?>
或者更好地使用
<?php $data = array();
if(isset($_POST))
{
foreach($_POST['check1'] as $rescheck)
{
$data[] = $rescheck
}
}
$this->db->insert_batch('mytable', $data);
?>
将所有复选框值存储在一列中:
$ check_value = implode(&#39;,&#39;,$ _ POST [&#39; check1&#39;]);
答案 1 :(得分:0)
试试这个:
$checkbox=$_POST['check1'];
for ($i=0; $i<count($checkbox);$i++) {
$query="INSERT INTO qe_qcc (checkbox) VALUES ('".$checkbox[$i]."')";
mysql_query($query) or die(mysql_error());
}
答案 2 :(得分:0)
你可以使用implode
$checkbox=implode(',', $_POST['check1']);
$query="INSERT INTO qe_qcc (checkbox) VALUES ('".$checkbox."')";
mysql_query($query) or die(mysql_error());
答案 3 :(得分:0)
<form name ="check" action="" method="POST">
<tr>
<td><input type="checkbox" name="check1[]" value="Enhance Productivity" />Enhance Productivity</td>
<td> <input type="checkbox" name="check1[]" value="Enhance Quality" />Enhance Quality</td>
<td> <input type="checkbox" name="check1[]" value="Save Time" />Save Time</td>
<td> <input type="checkbox" name="check1[]" value="Save Materials" />Save Materials</td>
<td> <input type="checkbox" name="check1[]" value="Save Stock" />Save Stock</td>
<td> <input type="checkbox" name="check1[]" value="Increase Safety" />Increase Safety</td>
<td> <input type="checkbox" name="check1[]" value="Financial Saving" />Financial Saving</td>
<td> <input type="checkbox" name="check1[]" value="Customer Friendly" />Customer Friendly</td>
<td> <br /><br /><input type="checkbox" name="check1[]" value="Others" />Others</td>
</tr>
<input type="submit" value="submit" />
</form>
在php中
<?php
if(isset($_POST['check1'])){
$check = $_POST['check1'];
foreach($check as $checked) {
$query="INSERT INTO qe_qcc (checkbox) VALUES ('".$checked."')";
mysql_query($query) or die(mysql_error());
}
}
?>