date increment problem
Posted: Thu Jan 19, 2006 3:52 pm
Hi,
I've got this code (below) that inserts 5 dates into a mysql database when one is selected. It picks up information from a form and loops through a for loop inserting 5 records incrementing the date by 7 days each time. The first date goes in fine but one the second time through it starts from 1999 eg if i select 2006-01-19 21:48:00 that will be inputted but the following four will be the following:
1999-11-26 09:48:00
1999-12-03 09:48:00
1999-12-10 09:48:00
1999-12-17 09:48:00
Whereas they should be:
2006-01-26 21:48:00
2006-02-02 21:48:00
2006-02-09 21:48:00
2006-02-16 21:48:00
I'm confident the error is in this line but I can't fix it.
I'd be grateful if you had any tips for me.
-Rob
I've got this code (below) that inserts 5 dates into a mysql database when one is selected. It picks up information from a form and loops through a for loop inserting 5 records incrementing the date by 7 days each time. The first date goes in fine but one the second time through it starts from 1999 eg if i select 2006-01-19 21:48:00 that will be inputted but the following four will be the following:
1999-11-26 09:48:00
1999-12-03 09:48:00
1999-12-10 09:48:00
1999-12-17 09:48:00
Whereas they should be:
2006-01-26 21:48:00
2006-02-02 21:48:00
2006-02-09 21:48:00
2006-02-16 21:48:00
I'm confident the error is in this line
Code: Select all
$date = date("Y-m-d h-i-s", mktime($hour, $min, $second, $month, $day + 7, $year));I'd be grateful if you had any tips for me.
-Rob
Code: Select all
$date = GetSQLValueString($_POST['lesson_datetime'], "date");
for ($i = 0; $i < 5; $i++)
{
$insertSQL = sprintf("INSERT INTO booking (bookingid, teacherid, studentid, roomid, lessontypeid, lesson_datetime, cancel) VALUES (%s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['bookingid'], "int"),
GetSQLValueString($_POST['teacherid'], "int"),
GetSQLValueString($_POST['studentid'], "int"),
GetSQLValueString($_POST['roomid'], "int"),
GetSQLValueString($_POST['lessontypeid'], "int"),
GetSQLValueString($date, "date"),
GetSQLValueString($_POST['cancel'], "text"));
mysql_select_db($database_connection, $connection);
$Result1 = mysql_query($insertSQL, $connection) or die(mysql_error());
$year = substr($date, 0, 4);
$month = substr($date, 5, 2);
$day = substr($date, 8, 2);
$hour = substr($date, 11, 2);
$min = substr($date, 14, 2);
$second = substr($date, 17, 2);
$date = date("Y-m-d h-i-s", mktime($hour, $min, $second, $month, $day + 7, $year));
}
}