So i have a table and a calculate button. the calculate button is responsible to selecting data from specific tables and then the selected data will be displayed and added together along with the calculation. but something is wrong with the process because it is not calculating correctly.
table & button:
<form method="post" action="expenses.php">
<center><table class="tform" border="1" rules="groups" cellpadding="6px" width="450px">
<colgroup></colgroup>
<thead>
<tr>
<th>Category</th>
<th>RM</th>
</tr>
</thead>
<tr>
<td><center>House</center></td>
<td><center><input type="text" name="janhouse" id="janhouse" size="11" readonly value="<?php if(@$query){echo htmlentities(@$htotal['htotal']);} ?>"></center></td>
</tr>
<tr>
<td><center>Personal</center></td>
<td><center><input type="text" name="janpersonal" id="janpersonal" size="11" readonly value="<?php if(@$query2){echo htmlentities(@$ptotal['ptotal']);} ?>"></center></td>
</tr>
<tfoot>
<tr>
<td><b><center>Total expenses for this month</center></b></td>
<td><center><input type="text" name="jantotal" maxlength="10" size="11" readonly value="<?php if(@$query4){echo htmlentities(@$etotal);} ?>"></center></td>
</tr>
</tfoot>
</table></center>
<center><input type="submit" value="Calculate" name="jancalc" id="calc" ></center>
</form>
the calculate button php:
if(isset($_POST['jancalc']))
{
require "connect.php";
$query=mysql_query("SELECT htotal FROM house");
$htotal=mysql_fetch_array($query);
$query2=mysql_query("SELECT ptotal FROM personal");
$ptotal=mysql_fetch_array($query2);
$query3=mysql_query("SELECT ttotal FROM transport");
$ttotal=mysql_fetch_array($query3);
if($htotal&&$ptotal&&$ttotal)
{
$etotal=($query + $query2 + $query3);
$query4=mysql_query("INSERT INTO january (ejant) VALUES ('$etotal')");
}
}
the data from each table is displayed correctly, as of now is it displaying 9, 8, 6 in its respective text boxes. but the total is wrong although it is displayed. the displayed total is 21 when actually 9+8+6=23.
i dont know whats wrong. the coding im using is pretty simple and sorta the same one i used in other pages. help please.