Jump to content

if statment help


scarface83

Recommended Posts

Hi,

 

can anyone see where im going wrong, im trying to build some validation into the absence_mgt.php form so that if the user doesn't select a team and advisor it send them back to the page with an error  but the absence_mgt2.php page is giving me trouble it echos the error but it still include the switch statement

 

Thanks

 

absence_mgt.php

<?

	session_start();
	if (isset($none_sel)) // if the loginerror variable is set then continue

			echo $none_sel; // 
			unset($_SESSION['none_sel']);	 // unregisters the session for  none_sel so it can be reset later in the script


	@$error = $_GET['error'];


	if($error=="3") {
			echo ("<h5><strong>.<br></strong></h5>");
			unset($error);  }
	if($error=="2") {
			echo ("<h5><strong>Select an option below before submitting.<br></strong></h5>");
			unset($error);  }
	if($error=="1") {
			echo ("<h5><strong>Please Select a Team/ Advisor First<br></strong></h5>");
			unset($error);  }


	require ('db_connect.inc'); // includes db connection details

	if(isset($teams)) { $set_teams = $_POST['teams']; }
		else { $set_teams="Please_Select";}

	$team_names = mysql_query("SELECT TeamRef,Teamname FROM a_team WHERE In_use='Y' AND TeamRef NOT LIKE '5'");

	if(isset($advisors)) { $set_advisors = $_POST['advisors']; }
		else { $set_advisors="Please_Select";}

	$advisor_names = mysql_query("SELECT nick FROM a_users WHERE In_use='Y' 	AND TeamRef='$set_teams' ORDER BY nick");	

	mysql_close();		

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Absence Managment</title>	
<link href="/incomplete/style.css" rel="stylesheet" type="text/css" />
</head>
<body>	

	<form name="select_advisor" method="post" action="absence_mgt.php">
	  <div class="driver2">
	    <table width="1383" border="0">
              <tr>
                <td width="1295"><div align="center"><span class="calendarToday"><b><u>Absence Management</u></b></span></div></td>
                <td width="78"><div align="right"><a href="main.php">Back</a> </div></td>
              </tr>
            </table>
	    
	    <table width="1395" border="0">
            <tr>
              <td width="865"><b><u>Please Select your team then advisor</u></b></td>
              </tr>
          </table>
	</div>
	</p>
	<table width="14%" border="1">
	<tr>
	<td width="78%"><div align="left">
	<select name="teams"> 

	<option value="Please_Select">Please Select</option> 


	<? 

	while($team_names_row = mysql_fetch_array($team_names)) {
	extract($team_names_row) 

	?>

	<? 

	if($set_teams==$TeamRef) { 

	?>
						  
	<option style="color:#FF0000" value="<? echo $TeamRef ?>" selected><? echo $Teamname; ?></option>

	<?	} else { ?>

	<option value="<? echo $TeamRef ?>"><? echo $Teamname; ?></option>

	<?	} ?>
	<?	} ?>

	</select>
	</div>
	</td>
	<td width="22%"><input type="submit" name="Submit" value="Select"></td>
	</tr>
	<tr>
	<td><div align="left">
               
	<select name="advisors">
      
                 
			  <option value="Please_Select">Please Select</option>
                  
                  <? while($advisor_names_row = mysql_fetch_array($advisor_names)) {
					extract($advisor_names_row) ?>
                  <? if($set_advisors==$nick) { ?>
                  <option style="color:#FF0000" value="<? echo $nick ?>" selected><? echo $nick; ?></option>
                  <?	} else { ?>
                  <option value="<? echo $nick ?>"><? echo $nick; ?></option>
                  <?	} ?>
                  <?	} ?>
          </select>
                <label></label>
              </div></td>
		  <td><input type="submit" name="Submit2" value="Select"></td>
      </tr></table>
	</form>
		<form name="form2" method="post" action="absence_mgt2.php">
		  <table width="310" border="0">
                <tr>
                  <td width="304"><p><strong><u>Please Select the Report to Run</u></strong></p>
                  </td>
                </tr>
              </table>
		  <br />
		  <table border="1">
  	<td width="56">
  	<input type="radio" name="whats_sel" value="1" /></td>
    <td width="161"><span class="style2">Absence Calendar </span></td>
  	</tr>
  	<tr>
    <td><input type="radio" name="whats_sel" value="2" /></td>
    <td class="style2">Stats</td>
  	</tr>
  	<tr>
    <td><input type="submit" name="Submit3" value="Submit"></td>
    <td><input type="hidden" value="<? echo $set_teams ?>" name="teams">
	<input type="hidden" value="<? echo $set_advisors ?>" name="advisors">
</td>
  	</tr>
    </table>
    </form>

</body>


 

absence_mgt2.php

 

<? session_start();

// include('sess_vars.php');

	$what_show = $_POST['whats_sel'];



	$team = 	$_POST['teams'] ;
	$advisor = $_POST['advisors'];
	$_SESSION['teams'] = $teams ;
	$_SESSION['advisors'] = $advisors ;


	if ($teams == "" ){
			$_SESSION['none_sel'];
	require ('absence_mgt.php');

}	elseif ($advisor ==""){	
			$_SESSION['none_sel'];
	require ('absence_mgt.php'); }





	require ('db_connect.inc');
	$query = mysql_query("SELECT Login,Forename,Surname FROM a_users WHERE In_use='Y' AND TeamRef='$team' AND nick='$advisor'")or die (mysql_error);

	$vtc = mysql_fetch_array($query);



	$vtc_login = $vtc['Login'];
	$first = $vtc['Forename'];
	$second = $vtc['Surname'];

	$_SESSION['vtc_login'] = $vtc_login ;
	$_SESSION['first'] = $first ;
	$_SESSION['second'] = $second ; 




	switch ($whats_sel) {

		case "1": include('new_cal.php'); exit(); break;
		case "2": include('abs_stats.php'); exit(); break;

	}

	echo "<meta http-equiv='refresh' content='0;URL=absence_mgt.php?error=2'>"; // refreshes the page to absence_mgt.php with error 2 if the above values are not met


exit();	
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
</body>
</html>

 

Link to comment
Share on other sites

How do I know whether it is error or right ?

 

according to your script

 

	switch ($whats_sel) {

		case "1": include('new_cal.php'); exit(); break;
		case "2": include('abs_stats.php'); exit(); break;

	}

 

When $whats_sel=="1", it will include new_cal.php, when =="2", include abs_stats.php.

 

So If you want to debug, go and check the value of the variable by using var_dump($whats_sel);

Link to comment
Share on other sites

So what is you problem again? every things seems working perfectly. Try to this and see....

 

	switch ($whats_sel) {

		case "1": include('new_cal.php'); exit(); break;
		case "2": include('abs_stats.php'); exit(); break;
                        default:   echo "<meta http-equiv='refresh' content='0;URL=absence_mgt.php?error=2'>"; break;

	}

Link to comment
Share on other sites

on the first page absence_mgt.php you select the team then the advisor then you select the report to run on that advisor (the radio buttons) what im stuck on is the if statements on <b>absence_mgt2.php</b>

 

i need validation so that if on the first page you say for example select the team but not the advisor the 2nd page redirects you back to the first , at  the moment  it just includes the file in stead of bouncing you back to the first page because you didnt select the team and or advisor , if you want i will pm the link to the site so you can look your self

 

thanks for your help

 

rob

 

 

Link to comment
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.