Jump to content

checkdate() if statement help please


dadamssg

Recommended Posts

im trying to check if a birthday exists and then to see if the birthday makes them older than 13...ive never used checkdate() before so yeah. i'm getting this error on the very first line

 

Parse error: syntax error, unexpected '{', expecting ')' on line 40

 

if(checkdate({$_POST['bmonth']}, {$_POST['bday']},{$_POST['byear']}))
    ///check to see if bday is valid and older than 13
{ 
   if(strtotime({$_POST['bmonth']}, {$_POST['bday']},{$_POST['byear']}) > 12299040000)
       	{
    $messages[]= "You must be at least 13 years of age to register.";
    }
}
else
///date is not valid
    {
$messages[]= "This date doesn't exist.";
}

Link to comment
https://forums.phpfreaks.com/topic/149342-checkdate-if-statement-help-please/
Share on other sites

<?php
if(checkdate($_POST['bmonth'], $_POST['bday'],$_POST['byear']))
    ///check to see if bday is valid and older than 13
{ 
   if(strtotime($_POST['bmonth'], $_POST['bday'],$_POST['byear']) > 12299040000)
        {
    $messages= "You must be at least 13 years of age to register.";
    }
}
else
///date is not valid
    {
$messages= "This date doesn't exist.";
}
?>

Improper use of "}" and "{"...

Birthday <select name='bmonth'> 
                                <option value=01>Jan
                                   <option value=02>Feb
                                     <option value=03>Mar
                                        <option value=04>Apr
                                        <option value=05>May
                                        <option value=06>Jun
                                        <option value=07>Jul
                                        <option value=08>Aug
                                        <option value=09>Sep
                                        <option value=10>Oct
                                        <option value=11>Nov
                                        <option value=12>Dec
                                                                </select>
		<select name='bday'>													
                                <option value=01>1
                                   <option value=02>2
                                     <option value=03>3
                                        <option value=04>4
                                        <option value=05>5
                                        <option value=06>6
                                        <option value=07>7
                                        <option value=08>8
                                        <option value=09>9
                                        <option value=10>10
                                        <option value=11>11
                                        <option value=12>12
                                        <option value=04>13 
<option value=04>14
<option value=04>15
<option value=04>16
<option value=04>17
<option value=04>18
<option value=04>19
<option value=04>20
<option value=04>21
<option value=04>22
<option value=04>23
<option value=04>24
<option value=04>25
<option value=04>26
<option value=04>27
<option value=04>28
<option value=04>29
<option value=04>30
<option value=04>31									</select>
<?php
/* build selection list for the year */
$today = time();
$startYr = date("Y", $today);  //get the year from $today
echo "<select name='syear'>\n";

$endYr = $startYr-90; // get the date you want to end up at
for ($syear=$startYr;$syear>=$endYr;$syear--)
{
echo " <option value=$syear";
if ($startYr == $syear )
{
	echo " selected";
}
echo "> $syear\n";
}
echo "</select>\n";
?>

same result...i don't think i have the checkdate part set up right,

 

 

//make date values integars 

  $bmonth = intval($_POST['bmonth']);
  $bday = intval($_POST['bday']);
  $byear = intval($_POST['byear']);
  
  
if(checkdate($bmonth, $bday, $byear))
    ///check to see if bday is valid and older than 13
{ 
   if(strtotime($bmonth, $bday, $byear) > 12299040000)
       	{
    $messages[]= "You must be at least 13 years of age to register.";
    }
}
else
///date is not valid
    {
$messages[]= "This date does not exist.";
}

if(strtotime("{$byear}-{$bmonth}-{$bday}") > 12299040000)

 

Or

 

if(mktime(0,0,0,$bmonth, $bday, $byear) > 12299040000)

 

Both should work, if not the second one should definately work. But why are you checking against a hard coded time code? That should be dynamic as well.

i tried this but same result...because 12299040000 is thirteen years old in seconds.

 

//make date values integars 

  $bmonth = intval($_POST['bmonth']);
  $bday = intval($_POST['bday']);
  $byear = intval($_POST['byear']);
  
$today = gmmktime(0,0,0,date('n'),date('j'),date('Y')); 
  $userbday = gmmktime(0,0,0,$bmonth,$bday,$byear);
  
  $difference = $today - $userbday;
  
if(checkdate($bmonth, $bday, $byear))
    ///check to see if bday is valid and older than 13
{ 
   if($difference > 12299040000)
       	{
    $messages[]= "You must be at least 13 years of age to register.";
    }
}
else
///date is not valid
    {
$messages[]= "This date does not exist.";
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.