Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 264
  • Last Modified:

Random 0 showing up after form filled out

On this page, http://bit.ly/pXD3H8, if you just hit submit and not fill anything in you'll see my error messages.

Any thoughts on why the "0" is showing up at the end of this line.

Please use the"BACK" button to try again.0

Code below.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Payday</title>
</head>
<style type="text/css">
body  {background-color:#9c9; margin:100px; font-size:36px; text-align:center; text-decoration:underline}
</style>

<body>

<?php
	
	
	function display($fieldName){
		echo "The field \"$fieldName\" is required.<br/>";
	}
	function validateWage($data, $fieldName){
		global $errorCount;
		if(empty($data)){
			display($fieldName);
			++$errorCount;
			$retval = "";
		}else{
			$retval = trim($data);
			$retval = stripslashes($retval);
			if (is_numeric($data)){
				$retval = round($data, 2);
			}else{
				echo "<p> Incorrect entry. You must enter a number.</p>";
				++$errorCount;
				$retval = "";
			}
			return($retval);
		}
	}
	$errorCount = 0;
	
	$wage =  validateWage($_POST['wage'], "Hourly wage");
	$hours = validateWage($_POST['hours'], "Hours worked");
	if ($errorCount>0){
		echo "Please use the\"BACK\" button to try again.";
	}else{
		 	echo "You Got PAID: $";
	}
	if ($hours>40){
		$OTHours = $hours - 40;
		$OT = $wage * .5;
		$pay = $wage * $hours;
		echo $OT * $OTHours + $pay;
	}else{
	$pay = $wage * $hours;
	echo $pay;
	}

?>
</body>
</html>

Open in new window

0
catonthecouchproductions
Asked:
catonthecouchproductions
1 Solution
 
Beverley PortlockCommented:
It looks to me like you have a misplaced { }. Instead of

     if ($errorCount>0){
          echo "Please use the\"BACK\" button to try again.";
     }else{
               echo "You Got PAID: $";
     }
     if ($hours>40){
          $OTHours = $hours - 40;
          $OT = $wage * .5;
          $pay = $wage * $hours;
          echo $OT * $OTHours + $pay;
     }else{
     $pay = $wage * $hours;
     echo $pay;
     }

Open in new window



it would make more sense to be like this

     if ($errorCount>0){
          echo "Please use the\"BACK\" button to try again.";
     }else{
               echo "You Got PAID: $";
               if ($hours>40){
                         $OTHours = $hours - 40;
                         $OT = $wage * .5;
                         $pay = $wage * $hours;
                         echo $OT * $OTHours + $pay;
               }else{
                    $pay = $wage * $hours;
                    echo $pay;
               }
     }

Open in new window

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now