Solved

Random 0 showing up after form filled out

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP/Magento not logging 2 35
Keep getting 503 on Curl request 6 31
only allow numbers with preg match 4 26
Checking if varaible is empty 6 30
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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.

920 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

12 Experts available now in Live!

Get 1:1 Help Now