need help with date compare

ckdoublenecks
10:26:10
I'm trying to retrieve an expiration date from a database and compare it to today's date. If the expiration date hasn't arrived yet, I want to redirect the program, if if it has I want to display a message.

<?php
mysql_connect(localhost,root,"");
mysql_select_db(expiredb) or die( "Unable to select database");
if(!empty($_POST["submit"]))
{
$noticedate = $_POST['noticedate'];
$expiredate = $_POST['expiredate'];
$query="SELECT noticedate,expiredate FROM entrydata";
$result=mysql_query($query);
if(mysql_num_rows($result))
{
$todays_date = date("Y-m-d");
$today = strtotime($todays_date);
$expiration_date = strtotime($expiredate);
if ($expiration_date > $today) {

header("Location: hammockoaks.html");
exit;
}
elseif ($expiration_date = $today) {
header("Location: hologo.html");
}else {
}
}// end of it statement for 'results found'
echo '_POST["submit"] is actually empty.';
}// end of if statement for no 'submit'
?>
smo1234
10-26-2010
You are trying to retrieve all the records, but in your case you will redirect in particular case only. I mean a particular record you will check against expire date and then redirect.

It is always better to use the query to collect the records than collect the record and then compare. So your query should be like this.

SELECT noticedate,expiredate FROM entrydata where expiredate > CURDATE()


This will display all records for which expire date is not yet arrived. You can change this to get all records which are expiring today.

SELECT noticedate,expiredate FROM entrydata where expiredate = CURDATE()

ckdoublenecks
10-27-2010
the only retrieval I'm making is the expiration date from the database. Then I want to execute one program or the other depending on whether the expiration date has been reached.
smo1234
10-27-2010
There are problems in the code.
1. You are getting the noticidate & expiredate from the form posting by not using inside the query. Query should be
select expiredate from entrydate where noticedat = '$noticedate'

2. You have to use mysql_fetch_object to get the expiredate and then you need not convert it into string, directly you can match with today.
ckdoublenecks
10-27-2010
until I get this going I'm not even using the noticedate field
Please Login to post your reply or start a new topic