heshan Posted August 16, 2012 Share Posted August 16, 2012 Hi All, I want to add data for the time tables. I have created 3 fields namely grade, class and stream which is only relevant for advanced level classes. otherwise the "stream" field should be disabled. In my database the class table and grade tables were already populated with data. But when i am trying to select from the drop down list no classes were get selected. It automatically selected grade "1" every time. I have posted my coding. Can anyone show me where i went wrong? <form name="form1" id="form1" method="get" action="addTimeTableValidation.php"> <?php $con=mysql_connect("localhost","root",""); mysql_select_db("student_management",$con); ?> <table width="850" border="1" align="center" bgcolor="#00FFFF"> <tr> <td colspan="2" valign="top"><table width="100%" cellpadding="0" cellspacing="0"> <tr> <td width="25%"><img src="../../IMAGE/banner - Copy.jpg" alt="" width="186" height="136" /></td> <td width="75%" align="center" valign="middle"><div align="center"><img src="../../IMAGE/banner.jpg" alt="" width="733" height="137" /></div></td> </tr> </table></td> </tr> <tr> <td width="170"> </td> <td width="676"><table width="663" border="0"> <tr> <td width="123"><a href="../../Home page/new student registration/add_or_manage.php">Manage Data</a></td> <td width="123"> </td> <td width="123"> </td> <td width="144" align="center"><a href="../../add admin users/changePasword.php">Change Password</a></td> <td width="134" align="center"><a href="../../Home page/new student registration/signout.php">Signout</a></td> </tr> </table></td> </tr> <tr> <td height="59" valign="top"><ul id="MenuBar1" class="MenuBarVertical"> <li><a href="../../add admin users/add techer/addAdminUser.php">Add Admin Login</a> </li> <li><a href="../../Student registration/new student registration/newStudentRegistrationForm.php">Add Student</a></li> <li><a href="../../student attendance/add attendance/addStudentAttendance.php">Add Student Attendance</a> </li> <li><a href="../../Student time table/add1 time table/addTimeTable.php">Add Time Table</a></li> <li><a href="../../Student marks/add student marks/addStudentMark.php">Add Student Marks</a></li> <li><a href="../../manage subject/add subject.php">Add Subject</a></li> <li><a href="../../search student information/SearchStudentInformation.php">Search Student Information</a></li> <li><a href="../../student payments reports/studentsPayments.php">Student Payment Reports</a></li> <li><a href="../../Issue certificate/issueCertificate.php">Issue Certificates</a></li> </ul> <p> </p> <p> </p></td> <td valign="top"><table width="659" border="0"> <tr> <td> </td> <td colspan="3"> </td> <td> </td> <td colspan="2"> </td> <td> </td> </tr> <tr> <td> </td> <td colspan="3"> </td> <td> </td> <td colspan="2"> </td> <td> </td> </tr> <tr> <td width="16"> </td> <td colspan="3"><h3> <label><strong>Add Time Table </strong></label> <strong> </strong></h3></td> <td> </td> <td colspan="2"> </td> <td> </td> </tr> <tr> <td colspan="2"> </td> <td colspan="2"> </td> <td width="91"> </td> <td colspan="2"> </td> <td width="206"> </td> </tr> <tr> <td> </td> <td width="117" align="center"><label>Greade</label> </td> <td width="69"> <select name="grade_ID" id="grade_ID" onchange="changefrm()" > <?php $grdid=isset($_POST['grade_ID']) ? $_POST['grade_ID'] :''; $query="SELECT * FROM grade"; $result=mysql_query($query); while($row = mysql_fetch_array($result)){ if($grdid==$row['grade_id']){ echo "<option selected value=\"".$row['grade_id']."\">".$row['grade']."</option> \n "; }else{ echo "<option value=\"".$row['grade_id']."\">".$row['grade']."</option> \n "; } } ?> </select></td> <td width="1" align="center"> </td> <td align="center"><label>Class</label> </td> <td width="71"> <select name="class_ID" id="jumpMenu2" > <?php $grdid=isset($_POST['grade_ID']) ? $_POST['grade_ID'] :''; $query="SELECT class_name FROM class where grade_id='$grdid'"; $result=mysql_query($query); while($row = mysql_fetch_array($result)) { echo "<option value=\"".$row['class_name']."\">".$row['class_name']."</option> \n "; } ?> </select> </td> <td width="69" align="center"><label>Stream</label> </td> <td><select name="stream_ID" id="jumpMenu3" <?php if(1<=$grdid && $grdid<=11){echo "disabled";}else{} ?>> <option>Maths</option> <option>Science</option> <option>Commerce</option> <option>Art</option> </select></td> </tr> <tr> <td colspan="2"> </td> <td colspan="2"> </td> <td> </td> <td colspan="2"> </td> <td> </td> </tr> <tr> <td colspan="2"> </td> <td colspan="2"> <input type="button" onclick="changefrm1()" name="button" id="button" value="Add" /> </td> <td> </td> <td colspan="2"> </td> <td> </td> </tr> </table> <p> </p> <p> </p></td> </tr> </table> </form> Quote Link to comment https://forums.phpfreaks.com/topic/267182-problem-arises-in-my-drop-down-list/ Share on other sites More sharing options...
JonnoTheDev Posted August 16, 2012 Share Posted August 16, 2012 Try this <?php $con = mysql_connect("localhost","root",""); mysql_select_db("student_management",$con); ?> <form name="form1" id="form1" method="get" action="addTimeTableValidation.php"> <table width="850" border="1" align="center" bgcolor="#00FFFF"> <tr> <td colspan="2" valign="top"><table width="100%" cellpadding="0" cellspacing="0"> <tr> <td width="25%"><img src="../../IMAGE/banner - Copy.jpg" alt="" width="186" height="136" /></td> <td width="75%" align="center" valign="middle"><div align="center"><img src="../../IMAGE/banner.jpg" alt="" width="733" height="137" /></div></td> </tr> </table></td> </tr> <tr> <td width="170"> </td> <td width="676"><table width="663" border="0"> <tr> <td width="123"><a href="../../Home page/new student registration/add_or_manage.php">Manage Data</a></td> <td width="123"> </td> <td width="123"> </td> <td width="144" align="center"><a href="../../add admin users/changePasword.php">Change Password</a></td> <td width="134" align="center"><a href="../../Home page/new student registration/signout.php">Signout</a></td> </tr> </table></td> </tr> <tr> <td height="59" valign="top"><ul id="MenuBar1" class="MenuBarVertical"> <li><a href="../../add admin users/add techer/addAdminUser.php">Add Admin Login</a> </li> <li><a href="../../Student registration/new student registration/newStudentRegistrationForm.php">Add Student</a></li> <li><a href="../../student attendance/add attendance/addStudentAttendance.php">Add Student Attendance</a> </li> <li><a href="../../Student time table/add1 time table/addTimeTable.php">Add Time Table</a></li> <li><a href="../../Student marks/add student marks/addStudentMark.php">Add Student Marks</a></li> <li><a href="../../manage subject/add subject.php">Add Subject</a></li> <li><a href="../../search student information/SearchStudentInformation.php">Search Student Information</a></li> <li><a href="../../student payments reports/studentsPayments.php">Student Payment Reports</a></li> <li><a href="../../Issue certificate/issueCertificate.php">Issue Certificates</a></li> </ul> <p> </p> <p> </p></td> <td valign="top"><table width="659" border="0"> <tr> <td> </td> <td colspan="3"> </td> <td> </td> <td colspan="2"> </td> <td> </td> </tr> <tr> <td> </td> <td colspan="3"> </td> <td> </td> <td colspan="2"> </td> <td> </td> </tr> <tr> <td width="16"> </td> <td colspan="3"><h3> <label><strong>Add Time Table </strong></label> <strong> </strong></h3></td> <td> </td> <td colspan="2"> </td> <td> </td> </tr> <tr> <td colspan="2"> </td> <td colspan="2"> </td> <td width="91"> </td> <td colspan="2"> </td> <td width="206"> </td> </tr> <tr> <td> </td> <td width="117" align="center"><label>Greade</label> </td> <td width="69"> <select name="grade_ID" id="grade_ID" onchange="changefrm()" > <?php $result = mysql_query("SELECT * FROM grade"); while($row = mysql_fetch_array($result)) { echo "<option value=\"".$row['grade_id']."\"".((isset($_POST['grade_ID']) && $_POST['grade_ID'] == $row['grade_id']) ? ' selected' : FALSE).">".$row['grade']."</option>\n"; } ?> </select> </td> <td width="1" align="center"> </td> <td align="center"><label>Class</label> </td> <td width="71"> <select name="class_ID" id="jumpMenu2" > <?php if(isset($_POST['grade_ID'])) { $result = mysql_query("SELECT class_name FROM class where grade_id='".mysql_real_escape_string($_POST['grade_ID'])."'"); while($row = mysql_fetch_array($result)) { echo "<option value=\"".$row['class_name']."\">".$row['class_name']."</option> \n "; } ?> </select> </td> <td width="69" align="center"><label>Stream</label> </td> <td> <select name="stream_ID" id="jumpMenu3"<?php if(isset($_POST['grade_ID']) && $_POST['grade_ID'] <= 11): echo " disabled"; endif; ?>> <option>Maths</option> <option>Science</option> <option>Commerce</option> <option>Art</option> </select> </td> </tr> <tr> <td colspan="2"> </td> <td colspan="2"> </td> <td> </td> <td colspan="2"> </td> <td> </td> </tr> <tr> <td colspan="2"> </td> <td colspan="2"> <input type="button" onclick="changefrm1()" name="button" id="button" value="Add" /> </td> <td> </td> <td colspan="2"> </td> <td> </td> </tr> </table> <p> </p> <p> </p></td> </tr> </table> </form> Quote Link to comment https://forums.phpfreaks.com/topic/267182-problem-arises-in-my-drop-down-list/#findComment-1369924 Share on other sites More sharing options...
heshan Posted August 16, 2012 Author Share Posted August 16, 2012 But still the same thing happens.... When i selected a particular grade it does not get selected. It is redirected to grade "1". No classes were displayed to select. My 2 tables are as follows. class (class_id, class_name, grade_id, stream) grade (grade_id, grade) Quote Link to comment https://forums.phpfreaks.com/topic/267182-problem-arises-in-my-drop-down-list/#findComment-1369926 Share on other sites More sharing options...
jazzman1 Posted August 16, 2012 Share Posted August 16, 2012 @off the neil.johnson's post is correct, check the values again. Quote Link to comment https://forums.phpfreaks.com/topic/267182-problem-arises-in-my-drop-down-list/#findComment-1369929 Share on other sites More sharing options...
Drummin Posted August 16, 2012 Share Posted August 16, 2012 Not sure, but isn't "class" a reserved word? Might need to change table name to "classes" or something. Quote Link to comment https://forums.phpfreaks.com/topic/267182-problem-arises-in-my-drop-down-list/#findComment-1369998 Share on other sites More sharing options...
jazzman1 Posted August 16, 2012 Share Posted August 16, 2012 He needs to check the values coming from $_POST['grade_ID'], but the form use GET method. There is js functions too, but I don't see ajax code...I don't know Quote Link to comment https://forums.phpfreaks.com/topic/267182-problem-arises-in-my-drop-down-list/#findComment-1370002 Share on other sites More sharing options...
Drummin Posted August 16, 2012 Share Posted August 16, 2012 He needs to check the values coming from $_POST['grade_ID'], but the form use GET method. There is js functions too, but I don't see ajax code...I don't know Of course, good spotting jazzman1. Unless you really need GET for some reason, change method to post. Quote Link to comment https://forums.phpfreaks.com/topic/267182-problem-arises-in-my-drop-down-list/#findComment-1370025 Share on other sites More sharing options...
heshan Posted August 17, 2012 Author Share Posted August 17, 2012 I changed the method to "POST" and now it seems they are working.. Thanks for everyone who help me out in this thread... Quote Link to comment https://forums.phpfreaks.com/topic/267182-problem-arises-in-my-drop-down-list/#findComment-1370158 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.