Jump to content

something is wrong in there...


Chris Val Kef

Recommended Posts

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]<?php

session_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)

Link to comment
Share on other sites

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.
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.