-1

I am quite new to php. Can somebody please guide me what is wrong with the code.

<?php
    if(!isset($_POST['submit']) || $_POST['submit']!="calculate")
    {
       $_POST['Contrib']="";
       $_POST['Currentage']="";
       $_POST['Retireage']="";
       $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;

       }

    }
    ?>

           <b>A Retirement Saving calculator</b>


           <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 want 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 = "5" NAME = "AnnGain"
                  value="<?php echo$AnnGain; ?>">
           <BR><BR>
           <p><b>Nest Egg </b>: <?php echo $Total; ?>
           <p><Input type = "submit" Name = "submit" value = "calculate">
           </form>
1
  • Fix the error mentioned by me and AndrewMurphey below and then post the full error message that you're getting (it should tell us the line number). Jan 18, 2010 at 7:17

3 Answers 3

0

In your code i see:

input type="test"

It is wrong, it should be:

input type="text"

Input type should be text if you mean a textbox.

1
  • Thanks for the typo. still the code is not working as expected Jan 18, 2010 at 7:08
0
   $_POST['Currentage']=="";
   $_POST['Retireage']=="";

You're checking if $_POST['Currentage'] is equal to "" instead of setting it to "". What you want is $_POST['Currentage'] = "";. You have the same problem with $_POST['Retireage'].

0

outside of the fact that modifying $_POST variables is bad practice (just assign those values to a variable and use that in your code)

  1. $_POST['Currentage']==""; should be $_POST['Currentage'] = '';
  2. $_POST['Retireage']==""; should be $_POST['Retireage'] = '';
  3. ALWAYS escape data using something like htmlentities() before you spit it out to the web browser to protect your page from injections. This is VERY important
1
  • Thanks for your suggestions. Still something is missing. Jan 18, 2010 at 7:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.