mrBen
11-28-2002, 10:34 AM
OK - this has me stumped.
Below is a script that adds dates into a booking table for the holiday cottage website that I administer. I can't see any problems with it, and yet for some unknown reason when I use it, it mysteriously changes from being Saturday dates to Friday days on the 1st November 2002. Without fail.
Hayelp.
<?
// add_dates2.php
// This file adds dates to the database up to the given date (but not including)
// Open the database connection
$connection = @mysql_connect ("localhost", "username", "se1<r3t" ) or die ("Unable to access bookings database" );
if ($connection) {
$msg = "Connected to Grinills Bookings Database" ;
}
$db = @mysql_select_db("mydatabase", $connection) or die ("Unable to access table");
// Grab the date from the form on the previous pag
$end_time=mktime(0,0,0, $month,$day,$year);
// Grab all the dates in numerical order
$sql = "select start from bookings order by start desc";
$result = @mysql_query($sql,$connection) or die ("Unable to access data");
$temparray = mysql_fetch_array($result);
// If there are dates in the table, then start from the last date
if ($temparray['start'] == 0) {
$day = "03";
$month = "08";
$year = "02";
}
else {
$year = substr ($temparray['start'], 0, 4);
$month = substr ($temparray['start'], 5, 2);
$day = substr ($temparray['start'], 8, 2);
}
// Double check the date is a Saturday
$error = (date("l", mktime(0,0,0,$month,$day,$year)) == "Saturday") or die("Internal date error");
// Start from the next weekend
$start_time=mktime(0,0,0,$month,$day,$year) + 604800;
while ($start_time < $end_time) {
$error = date("d-m-Y", $start_time);
$sql = "insert into bookings (start) values ('";
$sql .= date("Y-m-d", $start_time);
$sql .= "')";
$result = @mysql_query($sql,$connection) or die("Error adding date $error");
$start_time = $start_time + 604800;
}
?>
<html>
<head>
<title>Grinills -> Bookings -> Add Dates -> Added up to <? echo date ("l j M Y", $end_time) ?></title>
</head>
<body>
<img src="grinillsadminbanner.png"></img>
<center><h1>Adding dates....</h1></center>
Dates from <? echo date("l j M Y", mktime(0,0,0,$month,$day,$year)) ?> up until <? echo date("l j M Y", $end_time) ?> added.
<br><br>
<a href="booking_menu.php">Click here to return to Booking Menu</a>
</body>
</html>
Below is a script that adds dates into a booking table for the holiday cottage website that I administer. I can't see any problems with it, and yet for some unknown reason when I use it, it mysteriously changes from being Saturday dates to Friday days on the 1st November 2002. Without fail.
Hayelp.
<?
// add_dates2.php
// This file adds dates to the database up to the given date (but not including)
// Open the database connection
$connection = @mysql_connect ("localhost", "username", "se1<r3t" ) or die ("Unable to access bookings database" );
if ($connection) {
$msg = "Connected to Grinills Bookings Database" ;
}
$db = @mysql_select_db("mydatabase", $connection) or die ("Unable to access table");
// Grab the date from the form on the previous pag
$end_time=mktime(0,0,0, $month,$day,$year);
// Grab all the dates in numerical order
$sql = "select start from bookings order by start desc";
$result = @mysql_query($sql,$connection) or die ("Unable to access data");
$temparray = mysql_fetch_array($result);
// If there are dates in the table, then start from the last date
if ($temparray['start'] == 0) {
$day = "03";
$month = "08";
$year = "02";
}
else {
$year = substr ($temparray['start'], 0, 4);
$month = substr ($temparray['start'], 5, 2);
$day = substr ($temparray['start'], 8, 2);
}
// Double check the date is a Saturday
$error = (date("l", mktime(0,0,0,$month,$day,$year)) == "Saturday") or die("Internal date error");
// Start from the next weekend
$start_time=mktime(0,0,0,$month,$day,$year) + 604800;
while ($start_time < $end_time) {
$error = date("d-m-Y", $start_time);
$sql = "insert into bookings (start) values ('";
$sql .= date("Y-m-d", $start_time);
$sql .= "')";
$result = @mysql_query($sql,$connection) or die("Error adding date $error");
$start_time = $start_time + 604800;
}
?>
<html>
<head>
<title>Grinills -> Bookings -> Add Dates -> Added up to <? echo date ("l j M Y", $end_time) ?></title>
</head>
<body>
<img src="grinillsadminbanner.png"></img>
<center><h1>Adding dates....</h1></center>
Dates from <? echo date("l j M Y", mktime(0,0,0,$month,$day,$year)) ?> up until <? echo date("l j M Y", $end_time) ?> added.
<br><br>
<a href="booking_menu.php">Click here to return to Booking Menu</a>
</body>
</html>