PHP: Calling a function and passing a value to a variable?

I need to add a statement to the end of this script that calls the checkgrade() function and passes to it the value from the grade form variable. I have the form etc already programmed out, and I have a rough idea how to do this but I'm a little confused if I am on the right path or not. Here is my code, and how I think the statement should be written, but I would like another opinion or two before I try and finalise it on the server:
<?php
function checkGrade($Grade) {
switch ($Grade) {
case "A":
echo "Your grade is excellent.";
break;
case "B":
echo "Your grade is good.";
break;
case "C":
echo "Your grade is fair.";
break;
case "D":
echo "You are barely passing.";
break;
case "F":
echo "You failed.";
break;
default:
echo "You did not enter a valid letter grade.";
}
?>

statement:

function checkGrade($_GET["Grade"]


I have an HTML form I am using that has the Get action from this php, with a single text input named Grade.

2010-06-22T18:49:21Z

oops sorry missed a bracket on the end of the statement there.

2010-06-22T19:02:56Z

The code validates according to W3C.

2010-06-22T19:25:57Z

rb, I get an error in line 34 saying incorrect parsing.

I edited it to this:

function checkGrade($_GET["Grade"])// Call the function
$Grade = $_GET["Grade"];//pass the value from the form variable
echo "<p>$Grade</p>";

which then gave me an error in line 33.

2010-06-22T19:34:27Z

Ok its now telling me it is expecting a ")" in line 30, everything else is right but I don't seem to be missing a bracket, what am I missing?

rbjolly2010-06-22T19:06:04Z

Favorite Answer

Unfortunately, I did not check the code before I posted the first time. I had to add the "case" keyword for option C and drop the function keyword where I called the checkGrade function. This was easy enough to see when I copied the code into Netbeans. If you don't already use Netbeans, you might want to give it a try. See source link (there is a specific download version for PHP).

<?php
function checkGrade($Grade) {

switch ($Grade) {

case "A":
$msg = "Your grade is excellent.";
break;
case "B":
$msg = "Your grade is good.";
break;
case "C":
$msg = "Your grade is fair.";
break;
case "D":
$msg = "You are barely passing.";
break;
case "F":
$msg = "You failed.";
break;
default:
$msg = "You did not enter a valid letter grade.";
break;
}

return $msg;

}

// *** Now call your function.
if (isset($_GET["Grade"])) {

$grade = $_GET["Grade"];

echo(checkGrade($grade));

} else {

echo("Error. No grade selected.");

}

?>

?2010-06-23T01:54:24Z

try this reference:
http://www.w3schools.com/php/php_functions.asp