help on date

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

help on date

Post 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 :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

what's it doing?
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post 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...
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

Post 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..
Post Reply