Lassie Posted November 18, 2015 Share Posted November 18, 2015 I am trying to build a simple program to illustrate drawdown in a pension scenario. I have a syntax error that I cant find however. Any help appreciated. <?php if(!$_POST){ ?> <table border=1> <form action="" method="post"> <tr> <td> Initial Capital: <td> <input type="text" name="amount"> <td><br> <td> Growth Rate pa: (in %) <td> <input type="text" name="rate"> <td> Period in Yrs: <td> <input type="text" name="years" maxlength="4"> <td> Yearly Drawdown: <td> <input type="text" name="drawdown" maxlength="5"> <td> <input type="submit"> </form> </table> <?php }else{ if($_POST){ $amount = $_POST['amount']; $rate = $_POST['rate']; $time = $_POST['time']; $number = $_POST['years']; $drawdown = $_POST['drawdown']; $amount2 = (float)$amount; $rate2 = (float)$rate; $drawdown2 =(float)$drawdown; $year = 1 ?> <table border=1> <tr><td> Initial Capital: <?php echo "$start" ?></td> <td>Interest: <?php echo "$rate" ?>%</td> </table> <table border=1> <tr> <th>Years</th> <th>Amount</th> <th>Remaining Capital</th> </tr> <?php while ($year <= $number) { //calculate interest and deduct drawdown $Solve_Interest = ($amount2 * $rate2 * $time) / 100; $Total_Amount = ($amount2 + $Solve_Interest); $Remaining_Capital = ($Total_Amount - $drawdown2); echo "<tr><td>"; echo $year; echo "</td><td>"; echo "<tr><td>"; echo $Solved_Interest; echo "</td><td>"; echo "<tr><td>"; echo $Remaining_Capital; echo "</td><td>"; echo "</tr>"; $year = $year + 1; $amount2 = $Remaining_Capital; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/299514-cant-spot-syntax-error/ Share on other sites More sharing options...
Solution benanamen Posted November 18, 2015 Solution Share Posted November 18, 2015 (edited) Problem is here if($_POST){ Delete it. Your form tables are bad as well. All your tables are missing closing tags No closiing tr or td's, or table. And you shouldnt be using a tables for your forms. Use CSS. And you should probably switch around your if else post to if($_POST) instead of the negative if not post. Also, there is no need to create all those useless variables. Edited November 18, 2015 by benanamen Quote Link to comment https://forums.phpfreaks.com/topic/299514-cant-spot-syntax-error/#findComment-1526668 Share on other sites More sharing options...
Lassie Posted November 18, 2015 Author Share Posted November 18, 2015 Right. Thank you Quote Link to comment https://forums.phpfreaks.com/topic/299514-cant-spot-syntax-error/#findComment-1526669 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.