Checking mysql date against php date
Posted: Thu May 28, 2009 11:20 pm
I have a php script that inserts a set date into a table, it also inserts time every 6 minutes for x hours as well as an availability column. The first thing I do is check the database to make sure that the insert date has not already posted, if it has the else statement tells me that it has already been posted. Unfortunately I cannot get the date retrieved from mysql to equal the date in php
here is the code
any help would be appreciated, thanks
here is the code
Code: Select all
<?php
include "mysql.php";
$schddate = date('Y-m-d');
$open = '8:00';
$closed = '16:00';
$StartTime = strtotime($open);
$EndTime = strtotime($closed);
$availability = 4;
for($i = $StartTime; $i <= $EndTime; $i += 6 * 60) { //6 minutes. In this format it makes it easy to change the minutes
$temp_array[] = $i;
}
[color=#BF0000] $query = "SELECT schdDate FROM schedule " .[/color]
[color=#BF0000] "WHERE schdDate = " . $schddate . ";";[/color]
[color=#BF0000]$result = mysql_query ($query)[/color]
[color=#BF0000] or die(mysql_error());[/color]
[color=#BF0000]if (mysql_num_rows($result) != 0) {[/color]
echo "The schedule for that date has already been posted";
} else {
foreach ($temp_array as $time1) {
$time2 = date('H:i',$time1);
$query = "INSERT INTO schedule (schdDate, schdTime, schdAvail) " .
"VALUES ('" . $schddate . "','" . $time2 . "','" .
$availability . "');";
$result = mysql_query($query)
or die(mysql_error());
}
echo "The Schedule has been successfully posted ";
}
?>