Jump to content

Cant spot syntax error


Go to solution Solved by benanamen,

Recommended Posts

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;
}
	}
	?>


Link to comment
https://forums.phpfreaks.com/topic/299514-cant-spot-syntax-error/
Share on other sites

  • Solution

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 by benanamen
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.