我有2个复选框字段从表中获取数据。我想将它们都插入表中。我成功插入其中一个但当我尝试插入它们时我失败了。
我的表格:
<form action="select_role_insert.php" method="post" >
<label>Supervisor</label>
<?php
$reqm = "SELECT manager_name FROM manager_name ";
$repm = mysqli_query($dbc, $reqm);
while ($rowm = mysqli_fetch_array($repm))
{
$manager_name= $rowm['manager_name'];
?>
<input type="checkbox" name="Supervisor[]"
value="<?php echo $manager_name?>" /> <?php echo $manager_name?><hr/>
<?php
}
?>
<label>Speciality</label>
<?php
$req = "SELECT name FROM claims_follow_up.user_speciality";
$rep = mysqli_query($dbc, $req);
while ($row = mysqli_fetch_array($rep)) {
$name = $row['name'];
?>
<input type="checkbox" name="Speciality[]"
value="<?php echo $name?>" /> <?php echo $name ?><hr/>
<?php}?>
select_role_insert.php - 只插入一个变量的代码
$Speciality = $_POST['Speciality'];
foreach($Speciality as $i => $Speciality)
{
$carGroups = mysqli_query($dbc,"INSERT INTO
client_services SET Speciality ='$Speciality '");
}
请帮我插入主管和专业变量.. 提前致谢
答案 0 :(得分:-1)
看到解决方案,我发现它完美无缺。感谢您的建议
$Supervisor = $_POST['Supervisor'];
$Speciality2 = $_POST['Speciality'];
$arraye = array_combine($Supervisor, $Speciality2);
foreach($arraye as $k=> $a){
$carGroups = mysqli_query($dbc,"INSERT INTO claims_follow_up.client_services SET supervisor='$k', service='$a'");
}
答案 1 :(得分:-1)
您的表格:
<form action="select_role_insert.php" method="post" >
<label>Supervisor</label>
<?php
$reqm = "SELECT manager_name FROM manager_name ";
$repm = mysqli_query($dbc, $reqm);
while ($rowm = mysqli_fetch_array($repm))
{
$manager_name= $rowm['manager_name'];
?>
<input type="checkbox" name="Supervisor[]"
value="<?php echo $manager_name?>" /> <?php echo $manager_name?><hr/>
<?php
}
?>
<label>Speciality</label>
<?php
$req = "SELECT name FROM claims_follow_up.user_speciality";
$rep = mysqli_query($dbc, $req);
while ($row = mysqli_fetch_array($rep)) {
$name = $row['name'];
?>
<input type="checkbox" name="speciality_<?php echo $name?>"
value="<?php echo $name?>" /> <?php echo $name ?><hr/>
<?php}?>
select_role_insert.php - 插入以专业
开头的所有变量的代码 $Speciality = $_POST;
foreach($Speciality as $i => $Speciality)
{
if(substr($Speciality,0,10)=="speciality"){
$carGroups = mysqli_query($dbc,"INSERT INTO
client_services (Speciality) VALUES ('$Speciality')");
}
}