Solved

Random 0 showing up after form filled out

Posted on 2011-09-15
1
252 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to dynamically set the form action using jQuery.
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.

707 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

18 Experts available now in Live!

Get 1:1 Help Now