Solved

Random 0 showing up after form filled out

Posted on 2011-09-15
1
256 Views
Last Modified: 2012-05-12
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
Comment
1 Comment
 
LVL 34

Accepted Solution

by:
Beverley Portlock earned 500 total points
ID: 36546412
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now