I have one problem, while I am asking user for correction like so "Please enter numeric value for Income". however the value of Expenses disapper, and user have to enter it again. how can I make it so that it still save or maintains the already entered value for expenses while asking for correction of other fiels. Also, how come my print out is not displaying. Thanks in advance for your help
Income:
Expenses:
Debt:
Please enter numeric value for Income
+++++++++++++++++++++
Here is my code
Income:
Expenses:
Debt:
Please enter numeric value for Income
+++++++++++++++++++++
Here is my code
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title> Finance </title>
<style type="text/css" media="screen">.error {color: red ;} </style>
</head>
<body>
<form action="finance.php" method="post">
<p>Income: <input type="text"
name="income" size="10" /></p>
<p> Expenses: <input type="text"
name="expenses" size="10" /></p>
<p> Debt: <input type="text"
name="debt" size="10" /></p>
<input type="submit" name="submit"
value="Calculate" />
</form>
<?php
//flag variable to track success:
$okay = TRUE;
//check to see if there is value in income
if (empty($_POST['income'])) {
print '<p class="error"<The income field is empty, please complete</font>. </p>';
} elseif (!is_numeric($_POST['income'])){
print '<p class="error">Please enter numeric value for income </p>';
} elseif ($_POST['income'] < 0 ) {
print '<p class="error">Please enter non-negative income value. </p>';
} elseif (empty($_POST['expenses'])) {
print '<p class="error"<The Expenses field is empty, please complete</font>. </p>';
} elseif (!is_numeric($_POST['expenses'])){
print '<p class="error">Please enter numeric value for Expenses </p>';
} elseif ($_POST['expenses'] < 0 ) {
print '<p class="error">Please enter non-negative Expenses value. </p>';
} elseif (empty($_POST['debt'])) {
print '<p class="error"<The Debt field is empty, please complete</font>. </p>';
} elseif (!is_numeric($_POST['debt'])){
print '<p class="error">Please enter numeric value for Debt </p>';
} elseif ($_POST['expenses'] < 0 ) {
print '<p class="error">Please enter non-negative Debt value. </p>';
}
else {//Problem
print '<p class="error">Please complete all fields </p>';
$okay =FALSE;
}
if ($okay) {
print "<div><p>Your Income is $<span class=\"number\">$income</span><br />
Your Expenses is $<span class=\"number\">$expenses</span><br />
Your Debt is $<span class=\"number\">$debt</span><br /></p></div>";
}
?>
</body>
</html>