Am selecting some persons from form and setting a start and end date. While loop is working fine where the limit is set on date but foreach loop is not inserting the data. I have checked the ids of persons from check boxes are fetching perfectly just issue with insert query
<?php
include ('db.php');
$date_start = $_POST['date_start'];
$date_end = $_POST['date_end'];
$ids = $_POST['chk'];
$shift = $_POST['shiftTime'];
$conn = mysql_connect($servername,$database_username,$database_password);
if(!empty($date_start)){
//$date_change = DATE_FORMAT(NOW(),'%m-%d-%Y');
echo "Start date: $date_start"."<br>";
echo '<pre>';
print_r($_POST);
echo '</pre>';
$i=0;
while ($date_start<=$date_end){
echo "<br>".$i;
$date_start = date ("Y-m-d", strtotime("+1 day", strtotime($date_start)));
foreach ($ids as $val) {
$new_date = $date_start;
$sql1=mysql_fetch_assoc(mysql_query("Select * FROM user_shift_test WHERE userid='$val' "),$conn);
echo $e_id=$sql1['id'];
echo $e_name=$sql1['name'];
echo $e_dayoff=$sql1['dayoff'];
$query = mysql_query("INSERT INTO users_new_test (index,userid,id,name,shift,date_start,date_end,dayoff,updatetime) VALUES ('NULL','$ids[i]','$e_id','$e_name','$shift','$new_date','$date_end','$e_dayoff',now())");
}}
}
echo "<br>Successfully Inserted";
}
else{
echo "Nothing selected";
echo '<pre>';
print_r($_POST);
echo '</pre>';
}
?>