Code: Select all
<html>
<head>
<title></title>
</head>
<body style="font-family: Arial, Helvetica, sans-serif; color: black;">
<h1>My Bills</h1>
<form method=post>
<table>
<tr>
<th>Item</th>
<th>Amount</th>
</tr>
<?php
$total = "";
$amount_val = $error_text;
$error_text = $error_str;
for ($i = 1; $i < 5; $i++)
{
$counter++;
$error_str = "";
print "<br>i: $i";
$item_name = 'item'.$i;
$item_value = $_POST[$item_name];
$amount = 'amount'.$i;
$amount_value = $_POST[$amount];
$amount_val = trim($amount_value);
if (!empty($amount_val))
{
if (is_numeric($amount_val))
{
print "Add total amount<br>";
$total = $total + $amount_val;
}
if (!is_numeric($amount_val))
{
print "is not numeric number<br>";
//error_str is printing in all four feilds
$error_str = "<font color=red>'$counter'Amount '$amount_val' is not a number</font>";
$error_cnt++; //adds 1 to $error_cnt
}
}
print "<tr>";
print "<td><input type=text name=".$item_name." value='".$item_value."'></td>\n";
print "<td><input type=text name=".$amount." value='".$amount_value."'></td>\n";
print "<td>$error_str</td>\n";
print "</tr>\n";
}
?>
</table>
<?php
//need to work on getting this to switch right!
if (!empty($total))
{
if (is_numeric($total))
{
print "Add total amount<br>";
print "Total Bills:".$total;
}
} else {
print "Total Bills: 0<br>";
print "Empty<br>";
}
if (!is_numeric($amount_val))
{
print "Error count<br>";
print "<font color=red>Errors:$error_cnt</font>";
}
?>
<br><br><input type=submit value=Submit>
<br><br>
</form>
</body>
</html>