I'm trying to build a depreciation calculator that displays the value, year of use, and remaining value in table form like so: Purchase price of the Floor Pads = $10.00
(data entered in the first page) No. of years to depreciate = 5 Salvage Value = 0 Item:Floor Pads Cost:$10.00
(output on the second page)
Year Depreciation To Date Remaining Value
1 2.00 8.00
2 4.00 6.00
My issue is that I can't even begin to understand how I would update both the depreciation and the remaining value variables at the same time every time I recalculate them after they're incremented. There's nothing wrong with the html page, it's just the php page that's giving me trouble.The best I can get out of it is the error: Parse error: syntax error, unexpected variable "$i", expecting "," or ";" in C:\xampp\htdocs\deprecalc.php on line 65. My attempt at building these two pages is listed below (first the file which accepts the input, and then the file which outputs the results:
<!DOCTYPE html>
<html>
<head>
<title>Depreciation Calculator</title>
<link rel="stylesheet" type="text/css" href="main.css"/>
</head>
<body>
<div id="content">
<h1>Enter Your info</h1>
<form action="deprecalc.php" method="post">
<div id="data">
<label>Item name</label>
<input type="text" name="item_name"/>
</br>
<label>Purchase price</label>
<input type="text" name="purchase_price"/>
</br>
<label>No. of years</label>
<input type="text" name="no_of_years"/>
</br>
<label>Salvage value</label>
<input type="text" name="salvage_value"/>
</br>
</div>
<div id="buttons">
<label> </label>
<input type="submit" value="Calculate"></br>
</div>
</form>
</div>
</body>
</html>
//Here is the file that outputs the results
<?php
$item_name = $_POST['item_name'];
$purchase_price = $_POST['purchase_price'];
$no_of_years = $_POST['no_of_years'];
$salvage_value = $_POST['salvage_value'];
$depreciation = ($purchase_price - $remaining_value) / $no_of_years;
$remaining_value = $purchase_price - $depreciation;
?>
<!DOCTYPE html>
<html>
<head>
<title>Depreciation Calculator</title>
<link rel="stylesheet" type="text/css" href="main.css"/>
</head>
<body>
<div id="content">
<style>
#customers {
font-family: Arial, Helvetica, sans-serif;
border-collapse: collapse;
width: 100%;
}
#customers td, #customers th {
border: 1px solid #ddd;
padding: 8px;
}
#customers tr:nth-child(even){background-color: #f2f2f2;}
#customers tr:hover {background-color: #ddd;}
#customers th {
padding-top: 12px;
padding-bottom: 12px;
text-align: left;
background-color: navy;
color: white;
}
</style>
</head>
<body>
<h2>Item: <?php echo $item_name;?></h2></br>
<h2>Cost: <?php echo $purchase_price;?></h2></br>
<table id="customers">
<tr>
<th>Year</th>
<th>Depreciation to date</th>
<th>Remaining value</th>
</tr>
<tr>
<td><?php
$i=1;
while ($i <= $no_of_years){
echo "<td>"$i++"</td>";
}
?></td>
<td><?php
while ($remaining_value >= 0){
echo "<td>"$depreciation "</td>";
}
?></td>
<td><?php
while ($depreciation <= $purchase_price){
echo "<td>"$remaining_value"</td>";
}
?></td>
</tr>
</table>
</body>
</html>
</div>
</body>
</html>