Jump to content

PHP script


rswildy

Recommended Posts

Well I've only recently started learning PHP but yesterday i took about 5 hours writing a script, hah most people can do this in about 10 mins but it was hard getting all the correct details for the month year and calculating it all together ect. It's not very good but its my first one . I wanted to know if anything needs fixing here is the code.

<form method="GET" action="trynumber.php"><fieldset><legend><u>To find out how old you are fill in the following fields</u></legend><p><label for="y_old">How many Years old are you</label><br /><input type="text" name="y_old" size="3" /><br /><label for="m_old">How many Months old are you</label><br /><input type="text" name="m_old" size="2" /><br /><label for="d_old">How many days old are you</label><br /><input type="text" name="d_old" size="2" /> (Optional, Leave empty if you don't know)<br /><br /><br /><input type="submit" name="calcgo" value="calculate" /> </p></fieldset></form><?phpif ($_GET['calcgo'] == 'calculate') {$day   = $_GET['d_old'];$month = $_GET['m_old'];$year  = $_GET['y_old'];$ans_month   = ($year * 365.242199 / 30.4368499 + $month);$ans_week	= ($year * 365.242199 + $month * 30.4368499 + $day);$ans_day	 = ($year * 365.242199 + $month * 30.4368499 + $day);$ans_hours   = ($year * 365.242199 + $month * 30.4368499 + $day);$ans_seconds = ($year * 365.242199 + $month * 30.4368499 + $day);echo "You are " . $year . " years old." . "<br />";echo "You are " . round($ans_month) . " months old." . "<br />";echo "You are " . round($ans_week / 7) . " weeks old." . "<br />";echo "You are " . round($ans_day) . " days old." . "<br />";echo "You are " . round($ans_hours * 24) . " hours old." . "<br />";echo "You are " . round($ans_seconds * 24 * 60 ) . " Seconds old. " . "<br />";}?>

Please let me know what you think.Thanks, Rswildy.

Link to comment
Share on other sites

$ans_month   = ($year * 365.242199 / 30.4368499 + $month);

Hah! You must have studied (or are studying) science to know that there are 365.242199 days in a year. :)The only thing I see right away is that you misspelled label as "labal":
<labal for="y_old">How many Years old are you</label><br />
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...