Solved

Random 0 showing up after form filled out

Posted on 2011-09-15
1
259 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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 …

751 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