function checkdate accepting character value?????

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
om.bitsian
Forum Commoner
Posts: 36
Joined: Wed Sep 09, 2009 4:13 am

function checkdate accepting character value?????

Post by om.bitsian »

Hello friends
i am validating date field......it is accepting character value in my form
$BIRTH_DATE=($_POST['BIRTH_DATE']);
$BIRTH_MONTH=($_POST['BIRTH_MONTH']);
$BIRTH_YEAR=($_POST['BIRTH_YEAR']);
$date_birth = $BIRTH_YEAR."/".$BIRTH_MONTH."/".$BIRTH_DATE;
if(!checkdate($BIRTH_MONTH,$BIRTH_DATE,$BIRTH_YEAR))
{
die ('ERROR: Enter a valid birth date, the format is yyyy/mm/dd');
}


when i am entring 200h/1g/2f ..........the form is accepting even this value
out put is:
current date: 2009/09/22
birth date: 19809/2UTC/309

please help me to validate it properly
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: function checkdate accepting character value?????

Post by Mark Baker »

Use ctypeto validate your day, month and year values before calling checkdate().

And use selection lists in your form rather than text boxes... that way, you have more control over the day, month and year values that can be posted by normal users.... still validate with ctype and checkdate on the server though.
Post Reply