vinsux Posted July 24, 2012 Share Posted July 24, 2012 Guys i need your help again, i need an error-trapping code for registration, There's a course in the input field...and that's for studentsonly.. then the faculty must choose the "na", if the user didn't choose "na", it must have an error message that will output.. please help again..i understand the logic of my program but the code of database accepting only NA on faculty, i cant get it, i searched it on google, but still i can't find the solution... ..this is the code that i made .. no syntax error but it's still accepting any courses.. Thanks!!! if (empty($errors)){ switch($typecheck) { case "faculty" : if ($_POST['course'] != "na") { $errors .= "<font color=red><br /> *Course is for students only.</font>"; } } Quote Link to comment https://forums.phpfreaks.com/topic/266159-error-trapping/ Share on other sites More sharing options...
scootstah Posted July 24, 2012 Share Posted July 24, 2012 Where are $errors and $typecheck defined? Quote Link to comment https://forums.phpfreaks.com/topic/266159-error-trapping/#findComment-1363938 Share on other sites More sharing options...
vinsux Posted July 28, 2012 Author Share Posted July 28, 2012 Guys i need your help again, i need an error-trapping code for registration, There's a course in the input field...and that's for studentsonly.. then the faculty must choose the "na", if the user didn't choose "na", it must have an error message that will output.. please help again..i understand the logic of my program but the code of database accepting only NA on faculty, i cant get it, i searched it on google, but still i can't find the solution... ..this is the code that i made .. no syntax error but it's still accepting any courses.. Thanks!!! HERE's some of the code <?php //$dbconnect $errors=""; $message=""; if (isset($_POST['submit'])) { if (empty($errors)){ $allowed_types = array('students','faculty'); if (!in_array($_POST['type'],$allowed_types)){ $errors .= "<font color=red><br /> *Please select a valid account type.</font>"; }else{ $typecheck = $_POST['type']; } } //This is the code for error-trapping but its not working if (empty($errors)){ switch($typecheck) { case "faculty" : if ($_POST['course'] != "na") { $errors .= "<font color=red><br /> *Course is for students only.</font>"; } } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table border="0"> <tr> <th> *Course:</th> <th colspan="3"> <select name= "course"> <?php $courses = array( "na" => "---N.A.----", "bscs" => "B.S. Computer Science", "bsit" => "B.S. Information Technology", "bsba" => "B.S. Business Administration" ); foreach($courses as $key => $value){ $selected_course = (isset($_POST['course']) && $_POST['course']==$key ? 'selected="selected"' : ''); echo "<option value=\"$key\" $selected_course>$value</option>\r"; } ?> </select> </th> </tr> <tr> <th> Type of Account:</th> <th colspan="3"> <select name= "type"> <?php $atype = array( "students" => "Student", "faculty" => "Teacher" ); foreach($atype as $tkey => $tvalue){ $selected_type = (isset($_POST['type']) && $_POST['type']==$tkey ? 'selected="selected"' : ''); echo "<option value=\"$tkey\" $selected_type>$tvalue</option>\r"; } ?> </select> </th> </tr> </table> </form> Quote Link to comment https://forums.phpfreaks.com/topic/266159-error-trapping/#findComment-1365047 Share on other sites More sharing options...
PFMaBiSmAd Posted July 28, 2012 Share Posted July 28, 2012 I merged your threads for this together. If you already have an existing thread for a problem, don't start another thread for the same problem, especially if someone went to the trouble of reading your existing thread and asked a question about it in order to try and help. Quote Link to comment https://forums.phpfreaks.com/topic/266159-error-trapping/#findComment-1365052 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.