Unknown error when processing PHP form? -
below code simple form input/output. reason, question 1 seems working , questions 2 , 3 echo "something wrong." coded 3 questions exact same way throughout i'm not sure why question 2 , 3 aren't processing correctly. advice appreciated.
here html form:
<form action="processor.php" method="post"> <h4>question # 1</h4> <p>what grade in?</p> <label class="checkbox"><input type="checkbox" name="grade" value="1"> freshmen</label> <label class="checkbox"><input type="checkbox" name="grade" value="2"> sophomore</label> <label class="checkbox"><input type="checkbox" name="grade" value="3"> junior</label> <label class="checkbox"><input type="checkbox" name="grade" value="4"> senior</label> <h4>question # 2</h4> <p>what current gpa?</p> <select> <option name="gpa" value="4">3.5 or above</option> <option name="gpa" value="3">3.0-3.4</option> <option name="gpa" value="2">2.5-2.9</option> <option name="gpa" value="1">2.0-2.4</option> <option>lower</option> </select> <h4>question # 3</h4> <p>where excel academically?</p> <select multiple="multiple"> <option name="school" value ="1">mathematics</option> <option name="school" value ="2">literature</option> <option name="school" value ="3">history</option> <option name="school" value ="4">humanities</option> <option name="school" value ="5">science</option> </select> <div class="button"> <button class="btn btn-primary" input type="submit" name="submit" href="processor.php">submit</button> </div> </form> here processor:
<?php function grades () { $grade = $_post['grade']; if ($grade =="1") { echo "you're freshmen"; } elseif ($grade == "2") { echo "you're sophomore"; } elseif ($grade == "3") { echo "you're junior."; } elseif ($grade == "4") { echo "you're senior."; } else { echo "something wrong."; } } function gpa () { $gpa = $_post['gpa']; if ($gpa =="1") { echo "you need gpa."; } elseif ($gpa == "2") { echo "you're average student."; } elseif ($gpa == "3") { echo "you're above average student."; } elseif ($gpa == "4") { echo "you're excellent sudent."; } else { echo "something wrong."; } } function school () { $school = $_post['school']; if ($school =="1") { echo "you're math"; } elseif ($school == "2") { echo "you're lit"; } elseif ($school == "3") { echo "you're history."; } elseif ($school == "4") { echo "you're humanities."; } elseif ($school == "5") { echo "you're science."; } else { echo "something wrong."; } } include('viewpage.php'); ?> and view page:
<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>
the problem here
<select name="gpa"> <option value="4">3.5 or above</option> to access $_post['gpa'] <select> tag should have name property gpa not <option> tag
for $_post['school']
<select name="school" multiple="multiple"> <option value ="1">mathematics</option>
Comments
Post a Comment