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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IS_NUMERIC and ISSET not working(thanks for helping)

Status
Not open for further replies.

tekpr00

IS-IT--Management
Jan 22, 2008
186
CA
Hello:
These 2 functions are not working in the code below, please suggest any rectifications. The functions are IS_NUMERIC to check the values entered are numeric and ISSET to make sure that they submit values at all.

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> Tax Calc Form </title>
  <style type="text/css" media="screen">.number {font-weight: bold;} </style>
 </head>
 <body>

 <form action="taxcalc.php" method="post">

 <p> Enter Amount of Income <input type="text"
 name="amount" size="20" /></p>

<input type="submit" name="submit"
value="Submit" />
<h1> Tax Calculator </h1>
</form>
<?php 
/* This script takes values from above and use them in the function below. */
 //

if(isset($_POST['submitted'])){
}

//Variable starts Here
$amount=$_POST['amount'];

//Check amount range function 
function income_is_valid($amount){
if (is_numeric($_POST['amount']>0) AND is_numeric($_POST['amount'] < 1000000000)) {
$amt=$amount;
return $amt;
}  
else {
die('<p style="color:red;">This is not a VALID Amount. Please enter a value between 0 and 1 million!</p>');
}
}//end of range function

//tax rate function
function tax_rate($amount){
if ($amount<50000){
$tax_deduct=0;
  }
elseif(($amount>=50000) AND ($amount <= 500000)){
$tax_deduct=$amount*0.10;
		}
elseif($amount >500000){
$tax_deduct=$amount*0.15;
 }
 else{
 ;
  }		
 return $tax_deduct;		
}

//Call functions
$amt=income_is_valid($amount);
$tax_deduct=tax_rate($amount);
$net_pay=($amt - $tax_deduct);

else {
die('<p style="color:red;">Please enter a valid firstname, lastname, department and Jobtitle!</p>');
}

//print result
print "<p><div>
Pay Amount is :<span class=\"text\">$amt</span><br />
Your Tax Deduction is :<span class=\"text\">$tax_deduct</span><br />
Your Net Pay :  <span class=\"text\">$net_pay</span></p></div>"
?>
</body>
</html>
 
Does it help to validate the number range outside of the is_numeric function?

Code:
if (is_numeric($_POST['amount']) AND $_POST['amount'] > 0 AND $_POST['amount'] < 1000000000))

CCNP, CCNA Voice
 
yes that worked when i removed the last very last bracket as foollws:
Code:
if (is_numeric($_POST['amount']) AND $_POST['amount'] > 0 AND $_POST['amount'] < 1000000000)

Thanks

would you have a suggestion for ISSET?
 
It looks like your if(isset... code looks fine. The problem I see is that 1. The if statement isn't set to do anything. 2. You are checking for the post variable "submitted" but you never set it in the form. Try adding:
Code:
<input type="hidden" name="submitted" value="TRUE" />

CCNP, CCNA Voice
 
You were implicitly converting to a number inside each conditional (by adding the <>) thus is_numeric always returned the same.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top