Jump to content

Recommended Posts

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>";
}
}

Link to comment
https://forums.phpfreaks.com/topic/266159-error-trapping/
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/266159-error-trapping/#findComment-1365047
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/266159-error-trapping/#findComment-1365052
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.