Page 1 of 1

help on date

Posted: Tue Sep 06, 2005 4:39 am
by pleigh
i have a code here

Code: Select all

//check for project duration start date
	if (empty($_POST['startmonth']) || empty($_POST['startday']) || empty($_POST['startyear']))
    {
		if ($_POST['startmonth'] <= 0 || $_POST['startmonth'] >= 13 || $_POST['startday'] <= 0 || $_POST['startday'] >= 32 || $_POST['startyear'] <= 0 || $_POST['startyear'] >= 10000)
		{
        	$sd = false;
			$error['startmonth'] = '<font color=red />Please enter proper start date<br>';
		}
    }
    else
    {
        $sd = $_POST['startyear']."-".$_POST['startmonth']."-".$_POST['startday'];
    }
the idea is that when the textboxes are null, the $error will prompt....and if it is not null, it will check is the (month will not not be <= 0 or >= 13) or (day will not be <= 0 or >= 32) or (year will not be <= 0 or >= 10000) else, the error message will prompt the user....the problem with the above code is that, it does not work....please help me modify the above code....your help will be gladly apperciated....thanks in advance :)

Posted: Tue Sep 06, 2005 4:49 am
by feyd
what's it doing?

Posted: Tue Sep 06, 2005 4:53 am
by Maugrim_The_Reaper
First you're checking whether one of the 3 values are empty, if you get TRUE, you are then checking their ranges.

If a value is outside range, you create an error.

Problem is the range check, is inside the empty() check - so a range check is only made IF one of the values is empty...

Posted: Tue Sep 06, 2005 5:21 am
by pleigh
to feyd: this is for checking the range of the date and will limit the user from putting out of range data..

to Maugrim_The_Reaper:
yup..thanks, its working now...the range check is outside the empty() check...thanks again..