Jump to content

passing data to function


brem13

Recommended Posts

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

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.