Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

elseif statement

Status
Not open for further replies.

tekpr00

IS-IT--Management
Jan 22, 2008
186
CA
Hello All,

Can somone correct me what I am doing wrong here. Maybe I need a break from the staring at the screen. 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> Expences: <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. </p>';
} elseif (is_numeric($_POST['income'])){
    print '<p class="error">Please enter numeric value </p>';
} else {//Problem
	print '<p class="error">Please enter a value </p>';
	$okay =FALSE;
}

if ($okay) { 
	print '<p> </p>';
}

?>
</body>
</html>

however when testing only the Income field, it gives the reverse logic. when I put in 20 it asks me to "Please enter numeric value" like so
Income:20

Expences:

Debt:

Please enter a value
++++++++++++++++++++++

AND when I put in non-numeric it asks me to "Please enter a value" like so:

Income:rewrwer

Expences:

Debt:

Please enter a value

++++++++++++++

I was wondering if anyone can help with this logic
 
Please note that I will like to stick to the elseif statement becuase there other conditions I will like to test using the same elseif statement.
 
That's what you are telling it to do.

Code:
elseif (is_numeric($_POST['income'])){
is_numeric() returns true if the value is numeric. false if it is not numeric. So basically you are asking for a number when the value is a number.

Perhaps what you want is the inverse which would be:

Code:
elseif ([COLOR=red][b]![/b][/color]is_numeric($_POST['income'])){

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top