Chris Val Kef Posted November 24, 2006 Share Posted November 24, 2006 something is wrong with my code. All i want to do is a form with checkboxes where a student can update his lessons.if the checkbox is checked then the student send request to be registered (active=0). if the checkbox is empty and the student is registered (active=1) to the corresponding lesson then i want him to be deleted from it.here is a part of the form code[code]<td width="25"><div id="input"> <input type="hidden" name="hiddenCheck[]" value="{CLASS_ID}"> <input type="checkbox" name="check[]" value="{CLASS_ID}.{CNT}" {CHECKED}></div></td>[/code]and here is the action code...[code]<?phpsession_start();include '../config.php';$con = mysql_connect($dbServer,$dbUser,$dbPass) or exit("Error Connecting to Database");$sqlCLASSES = "SELECT id FROM classes";$resCLASSES = mysql_db_query("elearning",$sqlCLASSES);for ($cnt=0; $cnt<count($_POST["check"]); $cnt++){ $checked = $_POST["check"]["$cnt"]; $cntChecked = explode(".", $checked); $classID = $cntChecked[0]; for ($cnt2=0; $cnt2<count($_POST["hiddenCheck"]); $cnt2++) { if ( $cntChecked[1] == $cnt2) { $sqlREGISTERED = "SELECT id FROM student_attends_class WHERE (student_id = '".$_SESSION["student_id"]."') AND (class_id = $classID) AND (active = 1) "; $resREGISTERED = mysql_db_query ("elearning", $sqlREGISTERED); $resultREGISTERED = mysql_fetch_array ($resREGISTERED); if ( $resREGISTERED && (mysql_num_rows ($resREGISTERED) == 0) ) { $sqlSEMESTER = "SELECT semester FROM classes WHERE id = $classID "; $resSEMESTER = mysql_db_query ("elearning",$sqlSEMESTER); $resultSEMESTER = mysql_fetch_array ($resSEMESTER); $sqlREQUEST = "INSERT INTO student_attends_class VALUES ('', '$classID', '".$_SESSION["student_id"]."', '', '".$resultSEMESTER["semester"]."' )"; $resREQUEST = mysql_db_query ("elearning", $sqlREQUEST); } } else { $sqlREGISTERED = "SELECT id FROM student_attends_class WHERE (student_id = '".$_SESSION["student_id"]."') AND (class_id = '".$_POST["hiddenCheck"]["$cnt2"]."') AND (active='1') "; $resREGISTERED = mysql_db_query ("elearning", $sqlREGISTERED); $resultREGISTERED = mysql_fetch_array ($resREGISTERED); if ( $resREGISTERED && mysql_num_rows ($resREGISTERED) { $sqlUNREGISTER = "DELETE FROM student_attends_class WHERE class_id = '".$_POST["hiddenCheck"]["$cnt2"]."' "; $resUNREGISTER = mysql_db_query ("elearning", $sqlUNREGISTER); } } } }header ('Location: main.php?message=updated_lessons');?>[/code]the student can send his requests to register (active=0) without any problem but when his unchecks a lesson so to be deleted from it then he is deleted from the lesson and all the other lessons that he is registered to, coming to a state with 'active=0'.i can't fix it so far...Can someone please help me???? (before i'll finally change the whole 'concept' of the interface) Quote Link to comment https://forums.phpfreaks.com/topic/28373-something-is-wrong-in-there/ Share on other sites More sharing options...
Ninjakreborn Posted November 25, 2006 Share Posted November 25, 2006 If it's deleting everything then it's not reading your if statement correctly, it must be an empty variable or something, because if a delete query is issued on something, without a specifier it removes everything. Quote Link to comment https://forums.phpfreaks.com/topic/28373-something-is-wrong-in-there/#findComment-129840 Share on other sites More sharing options...
akitchin Posted November 25, 2006 Share Posted November 25, 2006 to be honest, i think a checkbox is ill-suited to your purpose here. i would suggest a dropdown box (<select>) or radio buttons (<input type="radio"... />), since you want to volley the user between two states. if you're having to add a hidden input for each checkbox, you aren't really saving yourself any time or effort over the more suitable options. Quote Link to comment https://forums.phpfreaks.com/topic/28373-something-is-wrong-in-there/#findComment-130047 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.