dskld5423 2017-02-14 06:26
浏览 16
已采纳

显示两个数组的值,并使用Mysql和php中的foreach将其保存在数据库中

I have two arrays, the array that holds the child name and the other one is an array that holds the birthday of the child. This is the design of my form that the user will fill up. enter image description here

<div id="Children">
  <div class="form-group col-md-7">
    <label for="child">Name of Child</label>
    <input type="text" class="form-control" name="child[]" id="child" placeholder="FULL NAME">
  </div>

  <div class="form-group col-md-5">
    <label for="ch_DateOfBirth">Date of Birth</label>
    <input type="text" class="form-control date-picker" name="ch_DateOfBirth[]" id="DateOfBirth" placeholder="Date of Birth">

  </div>

and this is my php code for saving the two arrays in the database.

$child_name=$_POST['child'];
$child_bday=date('Y-d-m', strtotime($_POST['ch_DateOfBirth']));
$count=count($child_name);

for ($i=0; $i < $count ; $i++) { 
  $sql6="INSERT into  tbl_children (Emp_ID, Ch_Name, Ch_Bdate) values ('".$emp_id."', '".$child_name[$i]."', '".$child_bday[$i]."') ";
    $dbcon->query($sql6);
}

but whenever i tried to do so, only the name of the children are saved excluding their birthdays. How can I save it using foreach if possible?

enter image description here

</div>
  • 写回答

1条回答 默认 最新

  • dongrong8972 2017-02-14 06:57
    关注

    Hope this will works

    $child_name=$_POST['child'];
    $count=count($child_name);
    
    for ($i=0; $i < $count ; $i++) {
      $child_bday=date('Y-d-m', strtotime($_POST['ch_DateOfBirth'][$i]));
      $sql6="INSERT into  tbl_children (Emp_ID, Ch_Name, Ch_Bdate) values ('".$emp_id."', '".$child_name[$i]."', '".$child_bday."') ";
      $dbcon->query($sql6);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂