error-trapping..

Codes here !

Moderators: macek, egami, gesf

vinsux
New php-forum User
New php-forum User
Posts: 9
Joined: Wed Jun 20, 2012 6:26 am

error-trapping..

Postby vinsux » Mon Jul 23, 2012 10:43 pm

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!!!


Code: Select all

if (empty($errors)){
switch($typecheck) {
case "faculty" :
if ($_POST['course'] != "na") {
$errors .= "<font color=red><br />&nbsp;&nbsp;*Course is for students only.</font>";
}
}

User avatar
Nullsig
php-forum Fan User
php-forum Fan User
Posts: 981
Joined: Thu Feb 17, 2011 6:52 am
Location: Racine, WI

Re: error-trapping..

Postby Nullsig » Tue Jul 24, 2012 4:26 am

Can you post more of the code, including the form that calls this script?

vinsux
New php-forum User
New php-forum User
Posts: 9
Joined: Wed Jun 20, 2012 6:26 am

Re: error-trapping..

Postby vinsux » Sat Jul 28, 2012 7:13 am

Code: Select all

<?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 />&nbsp;&nbsp;*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 />&nbsp;&nbsp;*Course is for students only.</font>";
}
}

?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
   <table border="0">
   <tr>
         <th>&nbsp;&nbsp;*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>&nbsp;&nbsp;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>


Return to “mySQL & php coding”

Who is online

Users browsing this forum: No registered users and 2 guests

cron