我有不同的复选框,如下面的代码所示,这段代码在我的最后工作正常,因为它连接所有选定的值并在DB中插入" PHP,.NET,JavaScript"等等,但我想要的是,如果我选择了3个复选框,它应该添加三个单独的条目1. PHP 2. JavaScript,3。Java。任何想法或概念都将受到赞赏。
make
答案 0 :(得分:1)
foreach($checkbox1 as $key => $value)
{
$in_ch=mysqli_query($con,"insert into new(time) values ('$value')");
}
希望它有所帮助!
答案 1 :(得分:1)
请尝试使用此
$checkbox1= $_POST["techno"];
foreach($checkbox1 as $key => $value){
$in_ch=mysqli_query($con,"insert into new(time) values ('$value')");
}
答案 2 :(得分:0)
您想要以逗号分隔的列表保存吗?
implode(",", $_POST["techno[]"]);
答案 3 :(得分:0)
感谢您的及时回复和想法。提到的代码工作正常,我得到了我想要的结果。
<html>
<body>
<form action="" method="post" enctype="multipart/form-data">
<div style="width:200px;border-radius:6px;margin:0px auto">
<table border="1">
<tr>
<td colspan="2">Select Technolgy:</td>
</tr>
<tr>
<td>PHP</td>
<td><input type="checkbox" name="techno[]" value="PHP"></td>
</tr>
<tr>
<td>.Net</td>
<td><input type="checkbox" name="techno[]" value=".Net"></td>
</tr>
<tr>
<td>Java</td>
<td><input type="checkbox" name="techno[]" value="Java"></td>
</tr>
<tr>
<td>Javascript</td>
<td><input type="checkbox" name="techno[]" value="javascript"></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="submit" name="sub"></td>
</tr>
</table>
</div>
</form>
<?php
if(isset($_POST['sub']))
{
$host="localhost";//host name
$username="root"; //database username
$word="";//database word
$db_name="dbtask";//database name
$tbl_name="new"; //table name
$con=mysqli_connect("$host", "$username", "$word","$db_name")or die("cannot connect");//connection string
$checkbox1=$_POST['techno'];
$chk="";
foreach($checkbox1 as $key => $value)
{
$in_ch=mysqli_query($con,"insert into new(time) values ('$value')");
echo'<script>alert("Inserted")</script>';
}
}
?>
</body>
</html>