Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Mine first calculator but something is wrong

Featured Replies

I have created this calculator but something is wrong and I don´tknow atm of how to fix it.

Here is the code;

 

<!DOCTYPE HTML>

<HEAD>

<TITLE>A POST example: retirement savings worksheet</TITLE>

<STYLE TYPE="text/css">

<!--

BODY {font-size:14pt}

.heading {font-size: 18pt; color:red}

-->

</style>

</HEAD>

 

<?php

//Samen met de waarde voor de knop Submit in onderstaand

//formulier, controleert deze test of het formulier voor de

//eerste keer wordt gerenderd (in dat geval wordt alleen de

//jaarlijkse groei ingevuld).

 

if (!IsSet($_POST['Submit']) || $_POST['Submit'] != 'Calculate')

{

$_POST['CurrentAge'] = "";

$_POST['RetireAge'] = "";

$_POST['Contrib'] = "";

$Total = 0;

$AnnGain = 7;

}else{

$AnnGain = $_POST['AnnGain'];

$Years = $_POST['RetireAge'] - $_POST['CurrentAge'];

$YearCount = 0;

$Total = $_POST['Contrib'];

 

while ($YearCount <= $Years) {

$Total = Round($Total * (1.0 + $AnnGain/100) +

$_POST['Contrib']);

$YearCount = $YearCount +1;

}}

?>

 

<BODY>

<DIV ALIGN="CENTER" ID="Div1" class="heading">

A retirement-saving calculator</div>

<p class=blurb>Fill all the values (except "Nest Egg")

and see how much money you'll have for your retirement

under different scenarios. You can change the values and

resubmit the form as many times as you like. You must fill

in the two "Age" variables. The "Anual reurn" variable has

a default inflation-adjusted value (7% = 8% growth minus 1%

inflation) which you can change to reflect your greater

optimism or pessimism</p>

 

<FORM ACTION="<?php echo $_SERVER['PHP_SELF']; ?>" METHOD="POST">

<P>Your age now:

<INPUT TYPE="text" SIZE=5 NAME="CurrentAge" VALUE="<?php echo $_POST['CurrentAge']; ?>">

<P>The age at which you plan to retire:

<INPUT TYPE="text" SIZE=6 NAME="RetireAge"VALUE="<?php echo $_POST['RetireAge']; ?>">

<P>Annual contribution:

<INPUT TYPE="text" SIZE=15 NAME="Contrib"VALUE="<?php echo $_POST['Contrib']; ?>">

<P>Annual Return:

<INPUT TYPE="text" SIZE=15 NAME="Contrib" VALUE="<?php echo $AnnGain; ?>"> %

<BR><BR>

<P><B>NEST EGG</B>: <?php echo $Total; ?>

<P><INPUT TYPE="submit" NAME="Submit" VALUE="Calculate">

</form>

</body>

</html>

 

I know I havn't specifeid a DOCTYPE this because it's just for the calculator.

Anyway there seems to be an error at;

<FORM ACTION="<?php echo $_SERVER['PHP_SELF']; ?>" METHOD="POST">

and at;

$AnnGain = $_POST['AnnGain'];

Maby some'one can figure out the issue?

You don't have an input field with name="AnnGain" so there is no value for $_POST['AnnGain'].

 

Looks like it's this line that's the problem:

<input type="text" size="15" name="Contrib" value="<?php echo $AnnGain; ?>" /> %

 

Oh, and <!DOCTYPE html> is fine. That's the standard HTML5 doctype!

 

And if you want my advice, stop coding everything in capital letters. It makes your code look amateurish and won't pass validation in XHTML standards.

Edited by Spitfire

  • Author

Alright thanks for the info, going to try to fix, and the cap highlight is just for mineself to have a better overview. Don´t worrie, won´t use cap when I´m to publish the scripts.

  • Author

It's fixed, thanks although there was another problem that I was able to found and correct it:)

1+ ;)

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.