我有兩個數組,其中包含子名稱的數組,另一個是保存子的生日的數組。 這是我的表單的設計,用戶將填滿。 顯示兩個數組的值,並將其保存在數據庫中使用foreach在Mysql和php中
<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>
,這是用於保存兩個數組在數據庫中我的PHP代碼。
$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);
}
但每當我試圖這樣做,只有孩子的名字都保存不包括他們的生日。如果可能,我如何使用foreach保存它?
檢查,看看閹了'$ child_bday'實際上包含的值,用'的print_r()'這個 –
我嘗試使用破滅(),它顯示值。 – Laurie
什麼是JavaScript中的日期格式,何時發送。它將需要發送日期,而不是字符串? –