dadamssg Posted March 14, 2009 Share Posted March 14, 2009 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 More sharing options...
WolfRage Posted March 14, 2009 Share Posted March 14, 2009 <?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 "{"... Link to comment https://forums.phpfreaks.com/topic/149342-checkdate-if-statement-help-please/#findComment-784345 Share on other sites More sharing options...
dadamssg Posted March 14, 2009 Author Share Posted March 14, 2009 hey thanks for that, but it will always say the date doesn't exist no matter what i date i put in...don't really know where to go from there Link to comment https://forums.phpfreaks.com/topic/149342-checkdate-if-statement-help-please/#findComment-784347 Share on other sites More sharing options...
WolfRage Posted March 14, 2009 Share Posted March 14, 2009 What are the following vars equal too please echo an example value for each. <?php echo $_POST['bmonth']; echo $_POST['bday']; echo $_POST['byear']; ?> Link to comment https://forums.phpfreaks.com/topic/149342-checkdate-if-statement-help-please/#findComment-784350 Share on other sites More sharing options...
dadamssg Posted March 14, 2009 Author Share Posted March 14, 2009 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"; ?> Link to comment https://forums.phpfreaks.com/topic/149342-checkdate-if-statement-help-please/#findComment-784352 Share on other sites More sharing options...
WolfRage Posted March 14, 2009 Share Posted March 14, 2009 You need to make these values integers; as of current they are strings because they came from $_POST. Use the below example for each $_POST: <?php $bmonth=intval($_POST['bmonth']); ?> Link to comment https://forums.phpfreaks.com/topic/149342-checkdate-if-statement-help-please/#findComment-784353 Share on other sites More sharing options...
dadamssg Posted March 14, 2009 Author Share Posted March 14, 2009 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."; } Link to comment https://forums.phpfreaks.com/topic/149342-checkdate-if-statement-help-please/#findComment-784569 Share on other sites More sharing options...
premiso Posted March 14, 2009 Share Posted March 14, 2009 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. Link to comment https://forums.phpfreaks.com/topic/149342-checkdate-if-statement-help-please/#findComment-784573 Share on other sites More sharing options...
dadamssg Posted March 14, 2009 Author Share Posted March 14, 2009 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."; } Link to comment https://forums.phpfreaks.com/topic/149342-checkdate-if-statement-help-please/#findComment-784581 Share on other sites More sharing options...
dadamssg Posted March 14, 2009 Author Share Posted March 14, 2009 anyone got any ideas? Link to comment https://forums.phpfreaks.com/topic/149342-checkdate-if-statement-help-please/#findComment-784853 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.