Hi all. I'm having an issue that I CAN NOT figure out for the life of me.
The program is to get user input about there paycheck , then calculate the answer.

What my problem is I can not get the php part to print anything inside the <?php?> tags. Not even a simple echo statement of my name will print out of I wipe the code and go from there. So maybe someone can see whats going on here and help me out.

Here's my code for the form:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Paycheck</title>
<meta http-equiv="content-type"
	content="txt/html; charset=iso-8859-1" />
</head>
<body>
<h1>Paycheck Calculation</h1>
<p>Please enter the hours you worked and your hourly wage in the appropriate text boxes. Then click
	the calculate button at the bottom to see how much you will make this week.</p>
<form action="Paycheck.php" method="get">
<p><b>Please enter the number of hours you worked this week including overtime.</b></p>
<input type="text" name="hoursWorked" size="15" maxlength="5" id="hours"/>
<p><b>Please enter your hourly wage.</b></p>
<input type="text" name="hourlyWage" size="15" maxlength="5" id="wage"/>
<p><input type="reset" id="reset" value="Reset" /></p>
<p><input type="submit" id="grossPay" value="Calculate" /></p>
</form>
</body>
</html>

Heres my code for the script:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Paycheck</title>
<meta http-equiv="content-type"
	content="txt/html; charset=iso-8859-1" />
</head>
<body>
<h1>Paycheck Results</h1>
<?php
/*
Shawn Houston
02/20/2010
*/
$hoursWorked = $_GET["hoursWorked"];
$hourlyWage = $_GET["hourlyWage"];

$hours = $hoursWorked;
$wage = $hourlyWage;
$pay = $grossPay;

if ($hours <= 40) {
	$submit = ("$hours * $wage = $pay");
	echo "Your gross pay is: $pay";
}
else
	$submit = ("($hours * $wage) + (($hours - 40) * ($wage * 1.5)) = $pay");
	echo "Your gross pay is: $pay";
?>
</body>
</html>

I have no idea whats going on here. Never ran into this before up until this point, and until then I can't even get my code cleaned up because I have no idea if anything is wrong.

see if using a single quotation inside of the GET makes a difference

see if using a single quotation inside of the GET makes a difference

Nope, still comes up blank.
The only thing that is printing out is the <h1>Paycheck Results</h1> then just a blank page.

Even if I put:

echo "Shawn Houston";

It either comes up blank or it prints it out as

Shawn Houston";
?>

but nothing else. My mind is officially boggled.

are the get values appearing in the URL?

Ok i think i see it.

You need to change your calculations to $pay = something + something

the way your doing it now is converting your get values to the value of pay which is nothing

Also, i dont understand the use of submit. You could just call it pay, then take pay out of the calculation.

Ok i think i see it.

You need to change your calculations to $pay = something + something

the way your doing it now is converting your get values to the value of pay which is nothing

The GET values are appearing in the URL

file:///C:/wamp/www/Paycheck.php?hoursWorked=45&hourlyWage=12.75

I went and changed it to:

$pay = ("$hours * $wage");

And its still just coming up a blank page besides the <h1>tag</h1>

I've went through and wiped out the code multiple times and just tried to get it to print out my name and it wont even do that. Wiped out both pages and redid them both line by line and it still just comes up with the same problem. Then I've tried to see if it was a problem else where but all my other pages work just fine.

Even if I try to just get it to print the get values with:

echo "<p>You worked: ", $_GET["hoursWorked"], "</p>";

It prints it out as :

You worked , $_GET["hoursWorked"], ""; ?>

try this

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Paycheck</title>
<meta http-equiv="content-type"
	content="txt/html; charset=iso-8859-1" />
</head>
<body>
<h1>Paycheck Results</h1>
<?php
/*
Shawn Houston
02/20/2010
*/
$hoursWorked = $_GET["hoursWorked"];
$hourlyWage = $_GET["hourlyWage"];

$hours = $hoursWorked;
$wage = $hourlyWage;
$pay = $grossPay;

if ($hours <= 40) {
	$pay = ($hours * $wage);
	echo "Your gross pay is:" . $pay;
}
else
	$pay = ($hours * $wage) + (($hours - 40) * ($wage * 1.5)));
	echo "Your gross pay is:" . $pay;
?>
</body>
</html>

try this

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Paycheck</title>
<meta http-equiv="content-type"
	content="txt/html; charset=iso-8859-1" />
</head>
<body>
<h1>Paycheck Results</h1>
<?php
/*
Shawn Houston
02/20/2010
*/
$hoursWorked = $_GET["hoursWorked"];
$hourlyWage = $_GET["hourlyWage"];

$hours = $hoursWorked;
$wage = $hourlyWage;
$pay = $grossPay;

if ($hours <= 40) {
	$pay = ($hours * $wage);
	echo "Your gross pay is:" . $pay;
}
else
	$pay = ($hours * $wage) + (($hours - 40) * ($wage * 1.5)));
	echo "Your gross pay is:" . $pay;
?>
</body>
</html>

blank page besides the <h1> tag aswell. Is there something else wrong on my end?

There is no form submit to invoke the php handler once the data is filled out.
PHP runs before the form is displayed, or again if "self" is invoked in the form action.
If you want "real time" results , you might want to look into javascript.

There is no form submit to invoke the php handler once the data is filled out.
PHP runs before the form is displayed, or again if "self" is invoked in the form action.
If you want "real time" results , you might want to look into javascript.

Not exactly sure what you mean here. Just trying to have a user enter their hours worked and wage, then go to a results page somewhat like a quiz and print out their gross pay.

I'm obviously missing something here. Once I enter the pay and hours, it flips to the results page. The GET values are in the URL however all its showing is the Paycheck Results heading and then a blank page no errors, nothing actually.

Tried to validate my code through the WDG validator comes back clean with no errors.

Do you mean I'm missing some sort of calling method when they hit the calculate button on the form page?

gota go to work now. will look when i get back

ok, had a hunch and it worked.

Dont know why, but i retyped (not copied and pasted) all of the code and it worked!!

Ive found sometimes in the past if somethings copied into an editor sometimes characters that look like a syntax character stop the code from working. For example there are a number of different kinds of " and at least 7 different single quotations.

and theres a problem with this line

//$pay = ($hours * $wage) + (($hours - 40) * ($wage * 1.5)));

Oops I didn't see the form part.
That output will just display at the top of the page in an unformatted way.
Ok for an experiment.
why do you $usehoursWorked then pass it ti $hours?
How about setting the $hours var equal to the $_GET and be done with it?
the same applies to to the $hourlyWage.

$pay = ($hours * $wage) + (($hours - 40) * ($wage * 1.5)));

too many parenthesis?

$pay = ($hours * $wage) + (($hours - 40) * ($wage * 1.5));

A white page indicates that the PHP code crashed.
Aren't you running with ERRORS_ON ?????? It would tell you.

and theres a problem with this line

//$pay = ($hours * $wage) + (($hours - 40) * ($wage * 1.5)));

Just not seeing it at this point. Retyped it and I must still be making the same syntax errors, but I did fix the line you have above.

Just getting the same blank page, maybe need to do the walk away and come back to it getting programming blindness :).

Oops I didn't see the form part.
That output will just display at the top of the page in an unformatted way.
Ok for an experiment.
why do you $usehoursWorked then pass it ti $hours?
How about setting the $hours var equal to the $_GET and be done with it?
the same applies to to the $hourlyWage.

$pay = ($hours * $wage) + (($hours - 40) * ($wage * 1.5)));

too many parenthesis?

$pay = ($hours * $wage) + (($hours - 40) * ($wage * 1.5));

A white page indicates that the PHP code crashed.
Aren't you running with ERRORS_ON ?????? It would tell you.

I see what your saying for setting $hours = $_GET["hoursWorked"];

As for running with ERRORS_ON, I "think" I am. What I mean by that is this is my first use with WAMP so not real sure where to turn it on and off to be completely honest, and if it even has anything to do with WAMP.

However, when I switch my code around even with setting it like above I still get the blank page, and have no idea how to even tell which line and where the program is going bonkers on me.

I see what your saying for setting $hours = $_GET["hoursWorked"];

As for running with ERRORS_ON, I "think" I am. What I mean by that is this is my first use with WAMP so not real sure where to turn it on and off to be completely honest, and if it even has anything to do with WAMP.

However, when I switch my code around even with setting it like above I still get the blank page, and have no idea how to even tell which line and where the program is going bonkers on me.

Ok found the settings in WAMP for the errors. I am running with them on however it doesn't kick up any errors. Error logs are blank, I'm not finding a thing. Validation doesn't kick up any errors, nothing.

You need an IDE. Grab a copy of NetBeans.
Code highlighting, and the other features makes this much less of a process.
You can set the error reporting in the php.ini file in doc root in the mean time.

You need an IDE. Grab a copy of NetBeans.
Code highlighting, and the other features makes this much less of a process.
You can set the error reporting in the php.ini file in doc root in the mean time.

I have netbeans, however how would I get it to work with PHP code compared to JAVA etc.

One line throws an error, while the next line is said to be just fine when its the same code.

You need an IDE. Grab a copy of NetBeans.
Code highlighting, and the other features makes this much less of a process.
You can set the error reporting in the php.ini file in doc root in the mean time.

Notice: Undefined index: hoursWorked in C:\wamp\www\Paycheck.php on line 16

Notice: Undefined index: hourlyWage in C:\wamp\www\Paycheck.php on line 17

Notice: Undefined variable: grossPay in C:\wamp\www\Paycheck.php on line 18
Your gross pay is:0Your gross pay is:0

Are the errors that are FINALLY popping up, Thanks much.

hoursWorked and hourlyWage are only coming up as undefined indexes due to me not opening the forum page and entering a value.

As for the grosspay() I can see why that is throwing an error I don't really have it set to anything. Which I will fix.

Notice: Undefined index: hoursWorked in C:\wamp\www\Paycheck.php on line 16

Notice: Undefined index: hourlyWage in C:\wamp\www\Paycheck.php on line 17

Notice: Undefined variable: grossPay in C:\wamp\www\Paycheck.php on line 18
Your gross pay is:0Your gross pay is:0

Are the errors that are FINALLY popping up, Thanks much.

hoursWorked and hourlyWage are only coming up as undefined indexes due to me not opening the forum page and entering a value.

As for the grosspay() I can see why that is throwing an error I don't really have it set to anything. Which I will fix.

OK now you are on your way to getting this figured out. ( nothing like having the right tools for the job -eh?)
Always be cognisant of the state of the variables. initially there is no $_get until you fill in the form and submit it.
use a trap for it.

if (isset $_get)
{
//do calculations
//set display vars to whatever // this invokes after the submit
}
else
{
//set display vars to "" //this is your first pass with no data
}

This way there is never an undefined condition.

OK now you are on your way to getting this figured out. ( nothing like having the right tools for the job -eh?)
Always be cognisant of the state of the variables. initially there is no $_get until you fill in the form and submit it.
use a trap for it.

if (isset $_get)
{
//do calculations
//set display vars to whatever // this invokes after the submit
}
else
{
//set display vars to "" //this is your first pass with no data
}

This way there is never an undefined condition.

Thanks. Appreciate all the help very much. One of my problems after stepping away and coming back was something so simple as my server not being online. So it wasn't working correctly from the local disk. After that I got it to work, and then started to play around a bit with the code you provided above to see the differences and clean my code up.

Again, thanks for the help guys.

If the vars are showing as advertised, please mark as solved, thanx

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.