brem13 Posted May 18, 2010 Share Posted May 18, 2010 hey, im trying to get a username from a database to be passed to a function as well as birthday information, however, the birthday information is working fine now but i cant get the username to pass over...any help? mysql_connect($server, $db_user, $db_pass) or die (mysql_error()); $result = mysql_db_query($database, "select * from $table") or die (mysql_error()); while($qry = mysql_fetch_array($result)){ $user = $qry['username']; $year = $qry['year']; $month = $qry['month']; $day = $qry['day']; $birthday = birthday($year."-".$month."-".$day); }//end while function birthday($birthday) { $age1 = htmlspecialchars($_POST['age1']); $age2 = htmlspecialchars($_POST['age2']); list($birth_year,$birth_month,$birth_day) = explode("-",$birthday); $year_diff = date("Y") - $birth_year; $month_diff = date("m") - $birth_month; $day_diff = date("d") - $birth_day; if ($month_diff < 0) $year_diff--; elseif (($month_diff==0) && ($day_diff < 0)) $year_diff--; if($year_diff >= $age1 && $year_diff <= $age2) echo $year_diff.$user; }//end birthday Link to comment https://forums.phpfreaks.com/topic/202165-passing-data-to-function/ Share on other sites More sharing options...
kenrbnsn Posted May 18, 2010 Share Posted May 18, 2010 You need to put a second parameter in the function definition and call the function using the new data: <?php function birthday($birthday,$user) ?> <?php $birthday = birthday($year."-".$month."-".$day, $user); ?> Ken Link to comment https://forums.phpfreaks.com/topic/202165-passing-data-to-function/#findComment-1060123 Share on other sites More sharing options...
brem13 Posted May 18, 2010 Author Share Posted May 18, 2010 thanks a lot man, i had tried function birthday($birthday,$user) but didnt try putting it in the other one, thank you Link to comment https://forums.phpfreaks.com/topic/202165-passing-data-to-function/#findComment-1060127 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.