Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
PHP passing a value from an HTML form?
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. Here is my code, I have updated it to show how I think it should be but I am still recieving an error.
<?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.";
}
$Grade = checkGrade
($Grade = $_GET["Grade"]);
echo "<p>$Grade</p>";
?>
I have an HTML form I am using that has the Get action from this php, with a single text input named Grade. Both validate on W3C. However I am getting an error parsing from the form to the function.
<!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%22%3E
<head>
<title> Letter Grades</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
</head>
<body>
<form action="LetterGrades.php" method="get">
<p>Grade: <Input type="text" name="Grade" />
<input type="submit" name="submit" value="Submit" /></p>
</form>
</body>
</html>
I KNOW the HTML I already have is correct. My problem is getting the info from the form variable to where it is needed in the.php file. I've used my php validator andI still get zip. Tried the suggestion here and it recieved syntax errors.
Here is what I've got for retrieving the form data in the php now.
If
$Grade = $_GET['Grade'] {
$Grade = checkGrade($Grade);
echo $Grade;
}
2 Answers
- JoelKatzLv 71 decade ago
You don't show either the form or the error, so I'm not sure how we can find the problem in it.
- Anonymous1 decade ago
In the HTML file:
<form ... action="grade.php" method="put"...
<input type="text" id="grade" />
In grade.php (your PHP file)
$grade = isset($_PUT['grade']) ? $_PUT['grade'] : '';
$grade = checkGrade($grade);
echo $grade;