Issue retrieving data from DB due to undefined variable

fifphrmble

New Member
My intention is to retrieve data from a database and have created the following functions but receive an undefined function, grades, error message. The code is as follows:\[code\] <form action="processor.php" method="post"> <h4>Question # 1</h4> <p>What grade are you in?</p> <label class="checkbox"><input type="checkbox" name="grade" value="http://stackoverflow.com/questions/15846872/1"> Freshmen</label> <label class="checkbox"><input type="checkbox" name="grade" value="http://stackoverflow.com/questions/15846872/2"> Sophomore</label> <label class="checkbox"><input type="checkbox" name="grade" value="http://stackoverflow.com/questions/15846872/3"> Junior</label> <label class="checkbox"><input type="checkbox" name="grade" value="http://stackoverflow.com/questions/15846872/4"> Senior</label> <h4>Question # 2</h4> <p>What is your current GPA?</p> <select name="gpa"> <option value="http://stackoverflow.com/questions/15846872/4">3.5 or above</option> <option value="http://stackoverflow.com/questions/15846872/3">3.0-3.4</option> <option value="http://stackoverflow.com/questions/15846872/2">2.5-2.9</option> <option value="http://stackoverflow.com/questions/15846872/1">2.0-2.4</option> <option value="http://stackoverflow.com/questions/15846872/0">Lower</option> </select> <h4>Question # 3</h4> <p>Where do you excel the most academically?</p> <select name="school" multiple="multiple"> <option value ="http://stackoverflow.com/questions/15846872/1">Mathematics</option> <option value ="http://stackoverflow.com/questions/15846872/2">Literature</option> <option value ="http://stackoverflow.com/questions/15846872/3">History</option> <option value ="http://stackoverflow.com/questions/15846872/4">Humanities</option> <option value ="http://stackoverflow.com/questions/15846872/5">Science</option> </select>\[/code\]Then the PHP file that processes the form submission:\[code\]<?phprequire_once('processor.php');class Processor { #codefunction get_response($id) {$dsn = "mysql:host=localhost;dbname=user";$username = "root"; // database username$password = "stewie12"; // database passwordtry { $enter = new PDO($dsn, $username, $password); $sql = "SELECT response FROM recommendations WHERE id = ? "; $new_item = $enter->prepare($sql); $new_item->setFetchmode(PDO::FETCH_ASSOC); $new_item->execute(array($id)); foreach($new_item as $nw) { return $nw['response']; }} catch (Exception $e) { echo $e->getMessage(); exit;}return ""; } function GetWeird () { $santiago="1992";if ($santiago="1992") { $id = 1; } else { $id = 2;} echo $this->get_response($id); } function Grades () { $grade = $_POST['grade']; if ($grade =="1") { echo "You're a freshmen";} elseif ($grade == "2") { echo "You're a sophomore";} elseif ($grade == "3") { echo "You're a junior.";} elseif ($grade == "4") { echo "You're a senior."; } else { echo "Something is wrong."; } } function Gpa () { $gpa = $_POST['gpa']; if ($gpa =="1") { echo "You strongly need to up your GPA."; } elseif ($gpa == "2") { echo "You're an average student."; } elseif ($gpa == "3") { echo "You're an above average student."; } elseif ($gpa == "4") { echo "You're an excellent sudent."; } else { echo "Something is wrong."; } } function School () { $school = $_POST['school']; if ($school =="1") { echo "You're into Math"; } elseif ($school == "2") { echo "You're into Lit"; } elseif ($school == "3") { echo "You're into history."; } elseif ($school == "4") { echo "You're into humanities."; } elseif ($school == "5") { echo "You're into science."; } else { echo "Something is wrong."; } }\[/code\]And the view page:\[code\] <?php $processor = new Processor(); ?> <h4>Question # 1</h4> <p><?php Grades($grade); ?></p> <h4>Question # 2</h4> <p><?php Gpa($gpa); ?></p> <h4>Question # 3</h4> <p><?php School($school); ?></p>\[/code\]
 
Back
Top