July 5, 201115 yr 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?
July 5, 201115 yr 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 July 5, 201115 yr by Spitfire
July 5, 201115 yr 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.
July 5, 201115 yr 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