y0y0y0 Posted May 27, 2009 Share Posted May 27, 2009 Hello. I am attempting to try my luck at PHP. I can not figure out how to call the function in the PHP code. I keep getting a blank page. I am using a simple html form with an input field and a submit button. When you enter in a particular letter grade, it should return a response based on their answer. Here are the bits of code. Thanks for any assistance. HTML: <!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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Letter Grades</title> </head> <body> <form action="LetterGrades.php" method="get" > <p> Grade: <input type="text" name="grade" /> <input type="submit" /> </p> </form> </body> </html> PHP: <!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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Letter Grades</title> </head> <body> <?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: return "You did not enter a valid letter grade."; } } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/159940-solved-help-calling-this-function-plz/ Share on other sites More sharing options...
MadTechie Posted May 27, 2009 Share Posted May 27, 2009 You don't need that function However to call it your do the following checkGrade($_GET['grade']); Quote Link to comment https://forums.phpfreaks.com/topic/159940-solved-help-calling-this-function-plz/#findComment-843534 Share on other sites More sharing options...
y0y0y0 Posted May 27, 2009 Author Share Posted May 27, 2009 Can you show me where to insert this call? Where ever I put it, I still keep getting a blank page. Thanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/159940-solved-help-calling-this-function-plz/#findComment-843556 Share on other sites More sharing options...
MadTechie Posted May 27, 2009 Share Posted May 27, 2009 Put this in a single file called LetterGrades.php <!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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Letter Grades</title> </head> <body> <form action="LetterGrades.php" method="get" > <p> Grade: <input type="text" name="grade" /> <input type="submit" /> </p> </form> <?php if(!empty($_GET['grade'])) checkGrade($_GET['grade']); ?> </body> </html> <?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: return "You did not enter a valid letter grade."; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/159940-solved-help-calling-this-function-plz/#findComment-843560 Share on other sites More sharing options...
y0y0y0 Posted May 27, 2009 Author Share Posted May 27, 2009 Thanks for the help! Quote Link to comment https://forums.phpfreaks.com/topic/159940-solved-help-calling-this-function-plz/#findComment-843563 Share on other sites More sharing options...
MadTechie Posted May 27, 2009 Share Posted May 27, 2009 Your very welcome. (and welcome to PHPFreaks) Oh and just so you know, without a function call it would look like 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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Letter Grades</title> </head> <body> <form action="LetterGrades.php" method="get" > <p> Grade: <input type="text" name="grade" /> <input type="submit" /> </p> </form> <?php if(!empty($_GET['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: return "You did not enter a valid letter grade."; } } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/159940-solved-help-calling-this-function-plz/#findComment-843569 Share on other sites More sharing options...
y0y0y0 Posted May 27, 2009 Author Share Posted May 27, 2009 Awesome. Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/159940-solved-help-calling-this-function-plz/#findComment-843573 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.