Hi Please Help with this code! The code gets information from text boxes on another page which is all done correctly, its then passed through a function and the results are saved as variables. I am trying to insert records into a database for each day missing weekends, for the length of a certain time period, $StartDate to $EndDate. Thanks any help would be appreciated.

```
<?php
session_start();

//Extract user data
$SelectedRoom = $_POST['Room'];
$Period1 = cleanString(trim($_POST['Period1']));
$Period2 = cleanString(trim($_POST['Period2']));
$Morning_Break =  cleanString(trim($_POST['Morning_Break']));
$Period3 = cleanString(trim($_POST['Period3']));
$Period4 = cleanString(trim($_POST['Period4']));
$Period5 = cleanString(trim($_POST['Period5']));
$Lunch1 = cleanString(trim($_POST['Lunch1']));
$Lunch2 = cleanString(trim($_POST['Lunch2']));
$Period6 = cleanString(trim($_POST['Period6']));
$Period7 = cleanString(trim($_POST['Period7']));
$Period8 = cleanString(trim($_POST['Period8']));

// create or open database called TimeTable.sqlite
$db = @sqlite_open("TimeTable.sqlite");
//Get Start Date from table
$sql = "SELECT fldStartDate FROM tblTermDate WHERE fldTerm_Name ='Christmas 1st Half'";
$res = sqlite_query($db, $sql);
if (sqlite_num_rows($res) > 0) {
    $StartDate = sqlite_fetch_single($res);
}
//Get End Date from Table
$sql = "SELECT fldEndDate FROM tblTermDate WHERE fldTerm_Name ='Christmas 1st Half'";
$res = sqlite_query($db, $sql);
if (sqlite_num_rows($res) > 0) {
    $EndDate = sqlite_fetch_single($res);   
}
// Finds the differnce between the days
$Days = (strtotime($EndDate) - strtotime($StartDate)) / 86400;
echo $Days;
if($db) {
    for($count = 0; $count = $Days; $count++) {
        // insert new booking
        for($counter = 1; $counter = 5; $counter++) {
            @sqlite_exec($db, "INSERT INTO tblBooking(fldRoom_ID, fldPeriod_ID, fldDate, fldBooking_Name, fldStaff_ID, fldComment) VALUES('" . $SelectedRoom . "',' Period_1 ','" . $StartDate . "','" . $Period1 . "',' '', '')");

            @sqlite_exec($db, "INSERT INTO tblBooking(fldRoom_ID, fldPeriod_ID, fldDate, fldBooking_Name, fldStaff_ID, fldComment) VALUES('" . $SelectedRoom . "',' Period_2 ','" . $StartDate . "','" . $Period2 . "',' '', '')");

            @sqlite_exec($db, "INSERT INTO tblBooking(fldRoom_ID, fldPeriod_ID, fldDate, fldBooking_Name, fldStaff_ID, fldComment) VALUES('" . $SelectedRoom . "',' Morning_Break ','" . $StartDate . "','" . $Morning_Break . "',' '', '')");

            @sqlite_exec($db, "INSERT INTO tblBooking(fldRoom_ID, fldPeriod_ID, fldDate, fldBooking_Name, fldStaff_ID, fldComment) VALUES('" . $SelectedRoom . "',' Period_3 ','" . $StartDate . "','" . $Period3 . "',' '', '')");

            @sqlite_exec($db, "INSERT INTO tblBooking(fldRoom_ID, fldPeriod_ID, fldDate, fldBooking_Name, fldStaff_ID, fldComment) VALUES('" . $SelectedRoom . "',' Period_4 ','" . $StartDate . "','" . $Period4 . "',' '', '')");

            @sqlite_exec($db, "INSERT INTO tblBooking(fldRoom_ID, fldPeriod_ID, fldDate, fldBooking_Name, fldStaff_ID, fldComment) VALUES('" . $SelectedRoom . "',' Period_5 ','" . $StartDate . "','" . $Period5 . "',' '', '')");

            @sqlite_exec($db, "INSERT INTO tblBooking(fldRoom_ID, fldPeriod_ID, fldDate, fldBooking_Name, fldStaff_ID, fldComment) VALUES('" . $SelectedRoom . "',' Lunch_1 ','" . $StartDate . "','" . $Lunch1 . "',' '', '')");

            @sqlite_exec($db, "INSERT INTO tblBooking(fldRoom_ID, fldPeriod_ID, fldDate, fldBooking_Name, fldStaff_ID, fldComment) VALUES('" . $SelectedRoom . "',' Lunch_2 ','" . $StartDate . "','" . $Lunch2 . "',' '', '')");

            @sqlite_exec($db, "INSERT INTO tblBooking(fldRoom_ID, fldPeriod_ID, fldDate, fldBooking_Name, fldStaff_ID, fldComment) VALUES('" . $SelectedRoom . "',' Period_6 ','" . $StartDate . "','" . $Period6 . "',' '', '')");

            @sqlite_exec($db, "INSERT INTO tblBooking(fldRoom_ID, fldPeriod_ID, fldDate, fldBooking_Name, fldStaff_ID, fldComment) VALUES('" . $SelectedRoom . "',' Period_7 ','" . $StartDate . "','" . $Period7 . "',' '', '')");

            @sqlite_exec($db, "INSERT INTO tblBooking(fldRoom_ID, fldPeriod_ID, fldDate, fldBooking_Name, fldStaff_ID, fldComment) VALUES('" . $SelectedRoom . "',' Period_8 ','" . $StartDate . "','" . $Period8 . "',' '', '')");

            $StartDate = strtotime($StartDate) + 86400;
        }
        $StartDate = strtotime($StartDate) + 172800;
        $count = $count + 2;
    }
    $_SESSION['WeeklyMessage'] = "Monday TimeTable Changed";
}
else {
    $_SESSION['WeeklyMessage'] = "Monday TimeTable Not Changed Error";
}
// close connection
@sqlite_close($db);

//return to previous webpage with message sent as session variable
header("Location: admin.php");

?>

```