scarface83 Posted March 12, 2007 Share Posted March 12, 2007 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> Quote Link to comment Share on other sites More sharing options...
scarface83 Posted March 12, 2007 Author Share Posted March 12, 2007 anyone ???? Quote Link to comment Share on other sites More sharing options...
donynam Posted March 12, 2007 Share Posted March 12, 2007 It seems that you never define $whats_sel before you use it. Try to initialize a variable before you use it, this can reduce a lot of problems. Quote Link to comment Share on other sites More sharing options...
scarface83 Posted March 12, 2007 Author Share Posted March 12, 2007 i defined it in absence_mgt2.php $whats_selected = $_POST['whats_sel']; is that what you mean ? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 12, 2007 Share Posted March 12, 2007 I see <?php $what_show = $_POST['whats_sel']; ?> but not <?php $whats_selected = $_POST['whats_sel']; ?> or <?php $whats_sel = $_POST['whats_sel']; ?> in absence_mgt2.php Ken Quote Link to comment Share on other sites More sharing options...
scarface83 Posted March 12, 2007 Author Share Posted March 12, 2007 Doh ! i thought you spotted it then but i have amended my mistake and its still the same ? Quote Link to comment Share on other sites More sharing options...
donynam Posted March 12, 2007 Share Posted March 12, 2007 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); Quote Link to comment Share on other sites More sharing options...
scarface83 Posted March 12, 2007 Author Share Posted March 12, 2007 i get string(1) "1" if no radio buttons are selected then string(1) "1" if the first radio button is selected and string(1) "2" if the 2nd radio button is selcted ? thanks Quote Link to comment Share on other sites More sharing options...
scarface83 Posted March 12, 2007 Author Share Posted March 12, 2007 the script should first check to see if the user has selected a team and a advisor if both values havent been selected it should stop and return to the absence_mgt.php page, but it seems like its skipping the if statements and just going to the switch Quote Link to comment Share on other sites More sharing options...
donynam Posted March 12, 2007 Share Posted March 12, 2007 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; } Quote Link to comment Share on other sites More sharing options...
scarface83 Posted March 12, 2007 Author Share Posted March 12, 2007 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 Quote Link to comment Share on other sites More sharing options...
donynam Posted March 12, 2007 Share Posted March 12, 2007 okay. You give me the link. Quote Link to comment Share on other sites More sharing options...
scarface83 Posted March 20, 2007 Author Share Posted March 20, 2007 hi all i still need help with this if there is anyone willing thanks Quote Link to comment 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.