eaglelegend Posted November 3, 2008 Share Posted November 3, 2008 I have noticed on my site, that users are 1 year younger than what they really are!! take a look at http://www.eaglelegend.com/ - register and look at your profile. here is the code: <?php /* User Profile (user_profile.php) */ $rank_check = 1; $page_title = "User Profile"; include "header.inc.php"; $members = fetch("SELECT * FROM members2 WHERE username = '$user' AND game = '$game'"); $members_profiles = fetch("SELECT * FROM members_profiles2 WHERE username = '$user' AND game = '$game'"); $online = fetch("SELECT last_visit FROM online WHERE userid = '$members[id]' ORDER BY last_visit DESC LIMIT 1"); if ($rank == "7") { $iplog = fetch("SELECT ip_addr FROM ip_log WHERE userid = '$members[id]' ORDER BY id DESC LIMIT 1"); $membersIP = " ($iplog[ip_addr])"; } if (!$members[id]) { die("$openHTML<p align=center class=error>That is not a real user</p>$closeHTML"); } if ($members[rank] <= 1) { die("$openHTML<p align=center class=error>This user has been suspended.</p>$closeHTML"); } $gender = $members_profiles[gender]; $genderArray = array("<img src=images/icons/undecided.gif>", "<img src=images/icons/female.gif>", "<img src=images/icons/male.gif>"); $gender = $genderArray[$gender]; $mailSettings = $members_profiles[mail_settings]; $mailSettingsArray = array( "<a href=mail_send.php?game=$game&send_to=$usersOn[username]><img src=images/icons/mail.gif></a>", "<a href=mail_send.php?game=$game&send_to=$usersOn[username]><img src=images/icons/mail.gif></a>", ""); $mailSettings = $mailSettingsArray[$mailSettings]; $bud = "<a href=buds.php?game=$game&bud=$members[username]><img src=images/icons/bud.gif></a>"; $date_registered = date("M j, Y", $members_profiles[date_registered]); $last_visited = date("H:i", $online[last_visit]); $last_visited2 = date("M j, Y @ H:i", $online[last_visit]); $exBday = explode("-", $members_profiles[birthday]); $months = array("", "January", "February", "March", "April", "May", "June", "July", "August", "Septemeber", "October", "November", "December"); $bdayMonth = $exBday[0]; if ($bdayMonth < 10) { $bdayMonth = ereg_replace("0", "", $bdayMonth); } $exBday[0] = $months[$bdayMonth]; $birthday = "$exBday[0] $exBday[1], $exBday[2]"; $userAge = $this_year - $exBday[2]; if ($this_month < $exBday[0]) { $userAge = $userAge - 1; } if (($this_month == $exBday[0]) AND ($today < $exBday[1])) { $userAge = $userAge - 1; } if ($online[last_visit] >= ($timestamp - $secondsToKeepUsersOn)) { $onlineNow = "<b><font color=green>Yes! <i><font size=-1>last visit at $last_visited</font></i></font></b>"; } else { $onlineNow = "<B><font color=red>No <i><font size=-1>last visit on $last_visited2</font></i></font></b></font></b>"; } $yourNotes = fetch("SELECT bud_note FROM buds2 WHERE bud_me = '$userid' AND bud_you = '$members[id]'"); $yourNotes = $yourNotes[bud_note]; if (!$yourNotes) { $yourNotes = "<i>You do not have any notes on the player, add them to your buddy list to add notes!</i>"; } $find_shop = fetch("SELECT shop_name,shop_size FROM usershops2 WHERE owner = '$members[id]' AND game = '$game'"); if ($find_shop[shop_name]) { $usershop_line = "<b>Shop:</b> <a href=$base_url/usershop.php?game=$game&user=$user>$find_shop[shop_name]</a> <font size=-1>(size $find_shop[shop_size])</font>"; } $find_gallery = fetch("SELECT gallery_name,gallery_size FROM usergallerys WHERE owner = '$members[id]' AND game = '$game'"); if ($find_gallery[gallery_name]) { $gallery_line = "<br><b>Gallery:</b> <a href=$base_url/usergallery.php?game=$game&user=$user>$find_gallery[gallery_name]</a> <font size=-1>(size $find_gallery[gallery_size])</font>"; } $locationLine = $members_profiles[location]; if (!$locationLine) { $locationLine = "<i>Middle of no where!</i>"; } $getClub = fetch("SELECT position,club FROM club_members2 WHERE user = '$members[id]' AND game = '$game'"); $getclub = fetch("SELECT id,name FROM clubs2 WHERE id = '$getClub[club]' AND game = '$game'"); if ($getclub[id]) { $clubrank = $getClub[position]; if ($clubrank == 1) { $position = "Member"; } if ($clubrank == 2) { $position = "Moderator"; } if ($clubrank == 3) { $position = "Admin"; } $club_line = "<br><b>Club:</b> $position in <a href=$base_url/club.php?game=$game&clubid=$getclub[id]>$getclub[name]</a>"; } $findPets = mysql_query("SELECT id,name,level FROM user_pets2 WHERE owner = '$members[id]' AND adoption = '0' AND game = '$game'"); $numUserPets = mysql_num_rows($findPets); $x = 1; while ($getPets = mysql_fetch_array($findPets)) { if ($x < $numUserPets) { $petList .= "<a href=user_pets.php?game=$game&id=$getPets[id]>$getPets[name]</a> (Lvl. $getPets[level]), "; } else { $petList .= "<a href=user_pets.php?game=$game&id=$getPets[id]>$getPets[name]</a> (Lvl. $getPets[level])"; } $x++; } echo <<<END $openHTML <table bgcolor=#ffffff width=95%> <tr><td> <CENTER> END; echo "<img src='uploads/$members_profiles[avatar_selected]' width=40 height=40> "; echo <<<END <FONT SIZE="+2"><B>$members[display_name]'s Profile</B></FONT></CENTER> <p>$members_profiles[profile]</p> <center><hr width=75% color="$tableOutline"></center> <font size=-1> <P><b>Username:</b> $members[display_name]$membersIP<br> <b>Real name:</b> $members_profiles[real_name]<bR> <b>Birthday:</b> $birthday ($userAge years old!)<br> <b>Location:</b> $locationLine<br> <b>Date Registered:</b> $date_registered<br> <b>Total Referrals:</b> $members_profiles[referrals]<br> <b>Total Posts:</b> $members[post_count] </P> <P><b>Your Notes:</b> $yourNotes</P> <P><b>$numUserPets Pets:</b> $petList</p> <P>$usershop_line<br> $club_line $gallery_line</p> <p><b>Online?</b> $onlineNow</P> </font> <center><table><tr><td> <form action=mail_send.php?game=$game&send_to=$members[username] method=post> <input type=submit value="Send Mail"> </form></td><td> <form action=buds.php?game=$game&bud=$members[username] method=post> <input type=submit value="Add to Buddy List"> </form></td></tr></table></center> </td></tr></table> $closeHTML END; ?> Quote Link to comment Share on other sites More sharing options...
F1Fan Posted November 3, 2008 Share Posted November 3, 2008 function birthDate($bdate){ $btime = strtotime($bdate); $byear = date('Y',$btime);//birth year $bmonth = date('m',$btime);//birth month $bday = date('d',$btime);//birth day $nyear = date('Y');//this year $years = $nyear-$byear;//number of years since birth year if (strtotime("$nyear-$bmonth-$bday")>time()){ $years--;//subtract one year if they haven't had a birthday yet this year } return $years; } echo birthDate('1987-12-01'); Quote Link to comment Share on other sites More sharing options...
F1Fan Posted November 3, 2008 Share Posted November 3, 2008 This function can be used to easily return an age in years. Your code: $exBday = explode("-", $members_profiles[birthday]); $months = array("", "January", "February", "March", "April", "May", "June", "July", "August", "Septemeber", "October", "November", "December"); $bdayMonth = $exBday[0]; if ($bdayMonth < 10) { $bdayMonth = ereg_replace("0", "", $bdayMonth); } $exBday[0] = $months[$bdayMonth]; $birthday = "$exBday[0] $exBday[1], $exBday[2]"; $userAge = $this_year - $exBday[2]; if ($this_month < $exBday[0]) { $userAge = $userAge - 1; } if (($this_month == $exBday[0]) AND ($today < $exBday[1])) { $userAge = $userAge - 1; } is overly complicated, and doesn't work. Replace it with this: function birthDate($bdate){ $btime = strtotime($bdate); $byear = date('Y',$btime);//birth year $bmonth = date('m',$btime);//birth month $bday = date('d',$btime);//birth day $nyear = date('Y');//this year $years = $nyear-$byear;//number of years since birth year if (strtotime("$nyear-$bmonth-$bday")>time()){ $years--;//subtract one year if they haven't had a birthday yet this year } return $years; } $userAge = birthDate($members_profiles['birthday']); Also, you should really use quotes for array keys (use $members_profiles['birthday'] instead of $members_profiles[birthday]). Quote Link to comment Share on other sites More sharing options...
eaglelegend Posted November 3, 2008 Author Share Posted November 3, 2008 Thats odd LOL I am 38?! XD I am only 16! http://eaglelegend.com/user_profile.php?game=1&user=maruku EDIT: All the users are. Quote Link to comment Share on other sites More sharing options...
F1Fan Posted November 3, 2008 Share Posted November 3, 2008 What format is your birthdate in? Try echoing various variables within the script and function to troubleshoot. This function has worked perfectly for several other users. Quote Link to comment Share on other sites More sharing options...
eaglelegend Posted November 3, 2008 Author Share Posted November 3, 2008 as in the american or english or as in md5? Quote Link to comment Share on other sites More sharing options...
F1Fan Posted November 3, 2008 Share Posted November 3, 2008 Huh? If you're referring to the date format, is it YYYY-MM-DD, or what? Quote Link to comment Share on other sites More sharing options...
eaglelegend Posted November 3, 2008 Author Share Posted November 3, 2008 MM -DD-YYYY Quote Link to comment Share on other sites More sharing options...
cpd Posted November 3, 2008 Share Posted November 3, 2008 Why not simply do: $dob = "24-04-1992"; function calcAge ($dob) { $tob = strtotime($dob); $age = date('Y') - date('Y', $tob); return date('md') < date('md', $tob) ? $age-1 : $age; } echo calcAge($dob); I cant remember where i saw how to do this but yer its a lot simplar and easier Quote Link to comment Share on other sites More sharing options...
F1Fan Posted November 3, 2008 Share Posted November 3, 2008 What is your birthday? I'm thinking it's not recognizing the date format as MM-DD-YYYY, but it see's it as DD-MM-YYYY. Quote Link to comment Share on other sites More sharing options...
eaglelegend Posted November 3, 2008 Author Share Posted November 3, 2008 18th May 1992... oe in american format MM DD YYYY Quote Link to comment Share on other sites More sharing options...
F1Fan Posted November 3, 2008 Share Posted November 3, 2008 So 05-18-1992? Try this: function birthDate($bdate){ $btime = strtotime($bdate); $byear = date('Y',$btime);//birth year $bmonth = date('m',$btime);//birth month $bday = date('d',$btime);//birth day $nyear = date('Y');//this year $years = $nyear-$byear;//number of years since birth year if (strtotime("$nyear-$bmonth-$bday")>time()){ $years--;//subtract one year if they haven't had a birthday yet this year } return $years; } $userAge = birthDate(strftime($members_profiles['birthday'],"%m-%d-%Y")); Not sure it that will work, because I've never used strftime before, but give it a go. Quote Link to comment Share on other sites More sharing options...
eaglelegend Posted November 3, 2008 Author Share Posted November 3, 2008 Still issiues; still 38 years old and this at the very top of the page; Warning: strftime() expects parameter 2 to be long, string given in user_profile.php on line 111 Quote Link to comment Share on other sites More sharing options...
AndyB Posted November 3, 2008 Share Posted November 3, 2008 Show us the code you are presently using and unambiguously give us an example of the date format you are using. Quote Link to comment Share on other sites More sharing options...
eaglelegend Posted November 3, 2008 Author Share Posted November 3, 2008 modified, or non modified? Quote Link to comment Share on other sites More sharing options...
eaglelegend Posted November 3, 2008 Author Share Posted November 3, 2008 Date format; MM DD YYYY Code; (edited by f1's code) <?php /* User Profile (user_profile.php) */ $rank_check = 1; $page_title = "User Profile"; include "header.inc.php"; $members = fetch("SELECT * FROM members2 WHERE username = '$user' AND game = '$game'"); $members_profiles = fetch("SELECT * FROM members_profiles2 WHERE username = '$user' AND game = '$game'"); $online = fetch("SELECT last_visit FROM online WHERE userid = '$members[id]' ORDER BY last_visit DESC LIMIT 1"); if ($rank == "7") { $iplog = fetch("SELECT ip_addr FROM ip_log WHERE userid = '$members[id]' ORDER BY id DESC LIMIT 1"); $membersIP = " ($iplog[ip_addr])"; } if (!$members[id]) { die("$openHTML<p align=center class=error>That is not a real user</p>$closeHTML"); } if ($members[rank] <= 1) { die("$openHTML<p align=center class=error>This user has been suspended.</p>$closeHTML"); } $gender = $members_profiles[gender]; $genderArray = array("<img src=images/icons/undecided.gif>", "<img src=images/icons/female.gif>", "<img src=images/icons/male.gif>"); $gender = $genderArray[$gender]; $mailSettings = $members_profiles[mail_settings]; $mailSettingsArray = array( "<a href=mail_send.php?game=$game&send_to=$usersOn[username]><img src=images/icons/mail.gif></a>", "<a href=mail_send.php?game=$game&send_to=$usersOn[username]><img src=images/icons/mail.gif></a>", ""); $mailSettings = $mailSettingsArray[$mailSettings]; $bud = "<a href=buds.php?game=$game&bud=$members[username]><img src=images/icons/bud.gif></a>"; $date_registered = date("M j, Y", $members_profiles[date_registered]); $last_visited = date("H:i", $online[last_visit]); $last_visited2 = date("M j, Y @ H:i", $online[last_visit]); function birthDate($bdate){ $btime = strtotime($bdate); $byear = date('Y',$btime);//birth year $bmonth = date('m',$btime);//birth month $bday = date('d',$btime);//birth day $nyear = date('Y');//this year $years = $nyear-$byear;//number of years since birth year if (strtotime("$nyear-$bmonth-$bday")>time()){ $years--;//subtract one year if they haven't had a birthday yet this year } return $years; } $userAge = birthDate(strftime($members_profiles['birthday'],"%m-%d-%Y")); if ($online[last_visit] >= ($timestamp - $secondsToKeepUsersOn)) { $onlineNow = "<b><font color=green>Yes! <i><font size=-1>last visit at $last_visited</font></i></font></b>"; } else { $onlineNow = "<B><font color=red>No <i><font size=-1>last visit on $last_visited2</font></i></font></b></font></b>"; } $yourNotes = fetch("SELECT bud_note FROM buds2 WHERE bud_me = '$userid' AND bud_you = '$members[id]'"); $yourNotes = $yourNotes[bud_note]; if (!$yourNotes) { $yourNotes = "<i>You do not have any notes on the player, add them to your buddy list to add notes!</i>"; } $find_shop = fetch("SELECT shop_name,shop_size FROM usershops2 WHERE owner = '$members[id]' AND game = '$game'"); if ($find_shop[shop_name]) { $usershop_line = "<b>Shop:</b> <a href=$base_url/usershop.php?game=$game&user=$user>$find_shop[shop_name]</a> <font size=-1>(size $find_shop[shop_size])</font>"; } $find_gallery = fetch("SELECT gallery_name,gallery_size FROM usergallerys WHERE owner = '$members[id]' AND game = '$game'"); if ($find_gallery[gallery_name]) { $gallery_line = "<br><b>Gallery:</b> <a href=$base_url/usergallery.php?game=$game&user=$user>$find_gallery[gallery_name]</a> <font size=-1>(size $find_gallery[gallery_size])</font>"; } $locationLine = $members_profiles[location]; if (!$locationLine) { $locationLine = "<i>Middle of no where!</i>"; } $getClub = fetch("SELECT position,club FROM club_members2 WHERE user = '$members[id]' AND game = '$game'"); $getclub = fetch("SELECT id,name FROM clubs2 WHERE id = '$getClub[club]' AND game = '$game'"); if ($getclub[id]) { $clubrank = $getClub[position]; if ($clubrank == 1) { $position = "Member"; } if ($clubrank == 2) { $position = "Moderator"; } if ($clubrank == 3) { $position = "Admin"; } $club_line = "<br><b>Club:</b> $position in <a href=$base_url/club.php?game=$game&clubid=$getclub[id]>$getclub[name]</a>"; } $findPets = mysql_query("SELECT id,name,level FROM user_pets2 WHERE owner = '$members[id]' AND adoption = '0' AND game = '$game'"); $numUserPets = mysql_num_rows($findPets); $x = 1; while ($getPets = mysql_fetch_array($findPets)) { if ($x < $numUserPets) { $petList .= "<a href=user_pets.php?game=$game&id=$getPets[id]>$getPets[name]</a> (Lvl. $getPets[level]), "; } else { $petList .= "<a href=user_pets.php?game=$game&id=$getPets[id]>$getPets[name]</a> (Lvl. $getPets[level])"; } $x++; } echo <<<END $openHTML <table bgcolor=#ffffff width=95%> <tr><td> <CENTER> END; echo "<img src='uploads/$members_profiles[avatar_selected]' width=40 height=40> "; echo <<<END <FONT SIZE="+2"><B>$members[display_name]'s Profile</B></FONT></CENTER> <p>$members_profiles[profile]</p> <center><hr width=75% color="$tableOutline"></center> <font size=-1> <P><b>Username:</b> $members[display_name]$membersIP<br> <b>Real name:</b> $members_profiles[real_name]<bR> <b>Birthday:</b> $birthday ($userAge years old!)<br> <b>Location:</b> $locationLine<br> <b>Date Registered:</b> $date_registered<br> <b>Total Referrals:</b> $members_profiles[referrals]<br> <b>Total Posts:</b> $members[post_count] </P> <P><b>Your Notes:</b> $yourNotes</P> <P><b>$numUserPets Pets:</b> $petList</p> <P>$usershop_line<br> $club_line $gallery_line</p> <p><b>Online?</b> $onlineNow</P> </font> <center><table><tr><td> <form action=mail_send.php?game=$game&send_to=$members[username] method=post> <input type=submit value="Send Mail"> </form></td><td> <form action=buds.php?game=$game&bud=$members[username] method=post> <input type=submit value="Add to Buddy List"> </form></td></tr></table></center> </td></tr></table> $closeHTML END; ?> Quote Link to comment Share on other sites More sharing options...
F1Fan Posted November 3, 2008 Share Posted November 3, 2008 OK, after testing it myself, I see that the problem is with the date format that you're using. Be extremely clear; What format is it in?? Is it "MM DD YYYY" or "MM-DD-YYYY" or something else? Quote Link to comment Share on other sites More sharing options...
eaglelegend Posted November 4, 2008 Author Share Posted November 4, 2008 in the databse, and upon registration - the format is MM DD YYYY however if it is helpful to you, perhaps it may be be good to try it DD MM YYYY? Perhaps it is like thaty format upon registration and database and perhaps it somehow changes whilst the file is being executed? Quote Link to comment Share on other sites More sharing options...
F1Fan Posted November 4, 2008 Share Posted November 4, 2008 The best format is YYYY-MM-DD. If you can't change it to that, you'll have to create logic to pull the YYYY, MM, and DD out. Quote Link to comment Share on other sites More sharing options...
eaglelegend Posted November 4, 2008 Author Share Posted November 4, 2008 if it isnt the databse or the code I had shown you controling what the format of age is - what is? Quote Link to comment Share on other sites More sharing options...
F1Fan Posted November 4, 2008 Share Posted November 4, 2008 It's your DB. You said this: ...however if it is helpful to you, perhaps it may be be good to try it DD MM YYYY?... To me, that says that you have control over it. If it is in the DB as a "date," then you should be able to extract it from the DB table in the proper format. Quote Link to comment Share on other sites More sharing options...
eaglelegend Posted November 4, 2008 Author Share Posted November 4, 2008 this is how it is in the database - 05-18-1992 thats my date of birth in the american format. so MM-DD-YYYY Quote Link to comment Share on other sites More sharing options...
F1Fan Posted November 4, 2008 Share Posted November 4, 2008 Is the data type of that column in the DB table a "date" format? Quote Link to comment Share on other sites More sharing options...
eaglelegend Posted November 4, 2008 Author Share Posted November 4, 2008 if you mean what I think you mean - no. it is "varchar(12)" Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 4, 2008 Share Posted November 4, 2008 Your database field should be a data type of "date" and stored as YYYY-MM-DD. Ken Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.