我想在数据库中存储多个复选框值,并且我的复选框名称不同,如何保存??。我有三个列,如调用它们,调用你,巡视,我如何将每个值存储在数据库中。< / p>
HTML Code
<input type="checkbox" name="Called_them[]" value="1">1<br>
<input type="checkbox" name="Called_them[]" value="2">2<br>
<input type="checkbox" name="Called_you[]" value="1">1<br>
<input type="checkbox" name="Called_you[]" value="2">2<br>
PHP代码: -
if(isset($_POST['submits']) )
{
$checked = $_POST['alled_them'];
$checked1 = isset($_POST['alled_them']);
for($i=0; $i < count($checked); $i++){
$tellfriend=new MemberEmails;
$tellfriend->called_them = isset($checked[$i])==0?'':$checked[i];
$tellfriend->save();
}
答案 0 :(得分:0)
$array_called_them = $_POST['called_them'];
$array_called_them = $_POST['called_you];
您现在将两个复选框组都作为数组。如果你想要数组中的值,只需在每个数组上使用foreach。
答案 1 :(得分:0)
if(isset($_POST["submit"])) {
foreach($_POST['called_them'] as $called_them) {
//do things
}
foreach($_POST['called_you'] as $called_you) {
// do things
}
}