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
pinehead18
Forum Contributor
Posts: 329 Joined: Thu Jul 31, 2003 9:20 pm
Post
by pinehead18 » Wed Aug 04, 2004 12:58 pm
Code: Select all
<?php
function checkCurAge($year,$month,$day='') {
$day=(empty($day))?'1':$day;
list($this_year, $this_month, $this_day) = explode(' ',date('Y n j'));
$age = $this_year - $year;
if($this_month<=$month && ($this_month==$month || $this_day<$day)) {
$age--;
}
return $age;
}
?>
This is my code and i get
Warning: Missing argument 1 for checkcurage()
and Warning: Missing argument 2 for checkcurage()
thank you
anthony
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Aug 04, 2004 1:03 pm
you're not calling it with those two arguments... what's the problem?
pinehead18
Forum Contributor
Posts: 329 Joined: Thu Jul 31, 2003 9:20 pm
Post
by pinehead18 » Wed Aug 04, 2004 2:03 pm
Those aruguements are set...
hawleyjr
BeerMod
Posts: 2170 Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA
Post
by hawleyjr » Wed Aug 04, 2004 2:04 pm
Post the rest of your code and put this in your function:
Code: Select all
<?php
echo '<PRE>'; print_r(func_get_args ()); echo '</PRE>';
?>
pinehead18
Forum Contributor
Posts: 329 Joined: Thu Jul 31, 2003 9:20 pm
Post
by pinehead18 » Thu Aug 05, 2004 2:40 pm
Question is did i enter that code in the right spot?
function checkCurAge($year,$month,$day='') {
echo '<PRE>'; print_r(func_get_args ()); echo '</PRE>';
$day=(empty($day))?'1':$day;
list($this_year, $this_month, $this_day) = explode(' ',date('Y n j'));
$age = $this_year - $year;
if($this_month<=$month && ($this_month==$month || $this_day<$day)) {
$age--;
}
return $age;
}
That is the code
Warning: Missing argument 1 for checkcurage() in /home/pinehead/www/myprofile on line 81
Warning: Missing argument 2 for checkcurage() in /home/pinehead/www/myprofile on line 81
Array
(
)
that is the output.
Thank you
Anthony
hawleyjr
BeerMod
Posts: 2170 Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA
Post
by hawleyjr » Thu Aug 05, 2004 2:42 pm
Please fix using PHP Tags. Its much easier to read.
hawleyjr
BeerMod
Posts: 2170 Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA
Post
by hawleyjr » Thu Aug 05, 2004 2:44 pm
Also, show us your code that is calling the function. You are not passing any variables to the function. If you were it would show up in the [php_man]print_r[/php_man]
pinehead18
Forum Contributor
Posts: 329 Joined: Thu Jul 31, 2003 9:20 pm
Post
by pinehead18 » Thu Aug 05, 2004 3:00 pm
That is probably the problem becuase i am setting the vars above the function, but i guess the function can't work unless the vars in the function call.
Newb! i am
pinehead18
Forum Contributor
Posts: 329 Joined: Thu Jul 31, 2003 9:20 pm
Post
by pinehead18 » Thu Aug 05, 2004 3:01 pm
Code: Select all
<?php
$month = $get_age[0];
$day = $get_age[1];
$year = $get_age[2];
function checkCurAge($year,$month,$day='') {
echo '<PRE>'; print_r(func_get_args ()); echo '</PRE>';
$day=(empty($day))?'1':$day;
list($this_year, $this_month, $this_day) = explode(' ',date('Y n j'));
$age = $this_year - $year;
if($this_month<=$month && ($this_month==$month || $this_day<$day)) {
$age--;
}
return $age;
}
checkCurAge($month,$date,$year);
?>
That is my code.
This is my output on the page.
Array
(
[0] => march
[1] =>
[2] => 1986
)
Thank you
Anthony
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Aug 05, 2004 3:41 pm
you didn't set $date now.. and is that the right order of arguments? your functions arguments are in a different order than your passing of variables..
pinehead18
Forum Contributor
Posts: 329 Joined: Thu Jul 31, 2003 9:20 pm
Post
by pinehead18 » Thu Aug 05, 2004 4:06 pm
can month = january or doe sit have to = 1 ?
hawleyjr
BeerMod
Posts: 2170 Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA
Post
by hawleyjr » Thu Aug 05, 2004 4:08 pm
Work with the [php_man]date[/php_man] function this will help.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Aug 05, 2004 4:10 pm
the way you are using it, it'd have to be numeric.. or at least, translated into a numeric.