Jump to content

Attendance system with Radio buttons


Jonas70

Recommended Posts

First of all I want to thank you in advance for your spending time to help me. I am making attendance form to my school with multiple radio buttons. Students and their classes are in a database and when a teacher chose class , let say class 7 then all students name of class 7 populate as a list in a table. And beside every student's name there will be three radio buttons to chose. Those's value will be Accepted , Not accepted , and Tardy. To poplate students I use Java function as below:(found in W3school) the first page. Let say populate.php

<html> 
<head> 
<script type="text/javascript"> 
function showUser(str) { if (str=="") 
{ 
document.getElementById("txtHint").innerHTML=""; return; 
}  
if (window.XMLHttpRequest) 
{
// code for IE7+, Firefox, Chrome, Opera, Safari 
xmlhttp=new XMLHttpRequest(); 
}
else 
{
// code for IE6, IE5 
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
} 
xmlhttp.onreadystatechange=function() 
{ 
if (xmlhttp.readyState==4 && xmlhttp.status==200) 
{ 
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
} 
} 
xmlhttp.open("GET","getuser.php?q="+str,true); 
xmlhttp.send(); 
} 
</script> 
</head> 
<body>  
<form> 
<select name="users" onchange="showUser(this.value)"> 
<option value="">Select a class:</option> <?php getClasses();  ?> </select>
</form> <br />  
</body> 
</html>  

   <?php // And the second page will be offcourse users.php and is as below:


$q=$_GET["q"];   
  $sql = "SELECT s.firstname, s.lastname, s.student_id, s.class_id, cl.class_id ".  
  " FROM students s ".  
  " INNER JOIN classes cl ON cl.class_id = s.class_id ". 
  " WHERE s.class_id =$q ";    
  $result = mysql_query($sql);  
  print '<table border="2">'. 
  '<tr>'. 
  '<th>Firstname</th>'. 
  '<th>Lastname</th>'. 
  '<th>Kind of absence</th>'.  
  '</tr>';  
  while($row = mysql_fetch_array($result)) 
  {  
    print  '<tr>'. 
    '<td>'.$row['firstname'].'</td>'. 
    '<td>'. $row['lastname'] . '</td>'. 
    '<td>'. '<form method="post" action="getuser.php">'.  
    '<input type="radio" name="attendance[]" value="1">Accepted</input>'.  
    '<input type="radio" name="attendance[]" value="2"> Not   accepted</input>'. 
    '<input type="radio" name="attendance[]" value="3"> Tardy</input>'.  
    '</form>'.   
    '</td>'.  
    '</tr>';  
    }  
    print '<tr>'. 
    '<td>'. 
    '<form method="post" action="getuser.php">'.  
    '<input type="submit" name="submit" value="Send"> &nbsp'. 
    '</form>'.  
    '</td>'.   

// I don't know where to put the submit button form.

print '</table>'; 
  //What I'am trying is to get all values of radio buttons and insert them in database.

if (isset($_REQUEST['submit']) && $_REQUEST['submit'] != "") 
{ if(isset($_POST['attendance'])) 
{  
    $atendance = $_POST['attendance'];  
    for ($i=0; $i<sizeof($attendance);$i++) 
    { 
        // I don't how but I know I have to collect student_id's too in array maybe here

$sql2 = " INSERT INTO absence (student_id, attendans_id  ) ". 
        " VALUES (".$student_id.", '".$attendance[$i]."') "; 
mysql_query($sql2) or die(mysql_error());  
}      
}  
}   

 

//So dear PHP lovers... I know I doing totaly wrong but I don't know how to fix this

problem and I would be greatful if you can help me. Thank you again in advance. There will be three radio buttons for teachers  to chose för every student. I mean Beside every student name there will be three alternativ to chose.... three radio buttons for every student with value accepted, not accepted and Tardy. Then collect all those value of buttons and student's id's and insert them in database.

 

I think I can collect student id's by doing this way:

while ($row_st = mysql_fetch_assoc($students)){
    
$studentarray[] = $row_st['student_id'];
}
//echo count($studentarray);
foreach($studentarray as $value)
{ 
    
//echo $value. "<br>";

$sql_stu = "INSERT INTO attendanse (student_id, absense_id) VALUES ('$value', '$absens_id')";
mysql_query($sql_stu) OR die(mysql_error());

// The problem is How can I get value of buttons, value of absence_id. Please Help! // Don't forget to see attached image b/c
one picture says 1000 words.
    
} 

 

 

 

 

post-133669-13482403476263_thumb.jpg

Link to comment
Share on other sites

There are loads of problems with what you have posted.  The most blatant issue is going to be how you have called your forms - there is one for every student.  The second issue is you are creating an array `attendance`, but you don't fill it with anything unique to identify it on the processing side. 

 

To answer some of your questions:

1) You put the submit button at the end of the form - wherever you want that to be.

2) Each student is going to have a value, look there

3) When you figure that out, it'll all make sense

Link to comment
Share on other sites

 

First of all I want to thank you in advance for your spending time to help me. I am making attendance form to my school with multiple radio buttons. Students and their classes are in a database and when a teacher chose class , let say class 7 then all students name of class 7 populate as a list in a table. And beside every student's name there will be three radio buttons to chose. Those's value will be Accepted , Not accepted , and Tardy. To poplate students I use Java function as below:(found in W3school) the first page. Let say populate.php

    
<html> 
<head> 
<script type="text/javascript"> 
function showUser(str) { if (str=="") 
{ 
document.getElementById("txtHint").innerHTML=""; return; 
}  
if (window.XMLHttpRequest) 
{
// code for IE7+, Firefox, Chrome, Opera, Safari 
xmlhttp=new XMLHttpRequest(); 
}
else 
{
// code for IE6, IE5 
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
} 
xmlhttp.onreadystatechange=function() 
{ 
if (xmlhttp.readyState==4 && xmlhttp.status==200) 
{ 
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
} 
} 
xmlhttp.open("GET","getuser.php?q="+str,true); 
xmlhttp.send(); 
} 
</script> 
</head> 
<body>  
<form> 
<select name="users" onchange="showUser(this.value)"> 
<option value="">Select a class:</option> <?php getClasses();  ?> </select>
</form> <br />  
</body> 
</html>  

   

 

// And the second page will be offcourse users.php and is as below:

 

<?php

$q=$_GET["q"];   
  $sql = "SELECT s.firstname, s.lastname, s.student_id, s.class_id, cl.class_id ".  
  " FROM students s ".  
  " INNER JOIN classes cl ON cl.class_id = s.class_id ". 
  " WHERE s.class_id =$q ";    
  $result = mysql_query($sql);  
  print '<table border="2">'. 
  '<tr>'. 
  '<th>Firstname</th>'. 
  '<th>Lastname</th>'. 
  '<th>Kind of absence</th>'.  
  '</tr>';  
  while($row = mysql_fetch_array($result)) 
  {  
    print  '<tr>'. 
    '<td>'.$row['firstname'].'</td>'. 
    '<td>'. $row['lastname'] . '</td>'. 
    '<td>'. '<form method="post" action="getuser.php">'.  
    '<input type="radio" name="attendance[]" value="1">Accepted</input>'.  
    '<input type="radio" name="attendance[]" value="2"> Not   accepted</input>'. 
    '<input type="radio" name="attendance[]" value="3"> Tardy</input>'.  
    '</form>'.   
    '</td>'.  
    '</tr>';  
    }  
    print '<tr>'. 
    '<td>'. 
    '<form method="post" action="getuser.php">'.  
    '<input type="submit" name="submit" value="Send"> &nbsp'. 
    '</form>'.  
    '</td>'.   

<?php     // I don't know where to put the submit button form.

print '</table>'; 
  //What I'am trying is to get all values of radio buttons and insert them in database.
[code]
<?php
if (isset($_REQUEST['submit']) && $_REQUEST['submit'] != "") 
{ if(isset($_POST['attendance'])) 
{  
    $atendance = $_POST['attendance'];  
    for ($i=0; $i<sizeof($attendance);$i++) 
    { 
?>        

// I don't how but I know I have to collect student_id's too in array maybe here
[code]
<?php
$sql2 = " INSERT INTO absence (student_id, attendans_id  ) ". 
        " VALUES (".$student_id.", '".$attendance[$i]."') "; 
mysql_query($sql2) or die(mysql_error());  
}      
}  
}   

?>

//So dear PHP lovers... I know I doing totaly wrong but I don't know how to fix this

problem and I would be greatful if you can help me. Thank you again in advance. There will be three radio buttons for teachers  to chose för every student. I mean Beside every student name there will be three alternativ to chose.... three radio buttons for every student with value accepted, not accepted and Tardy. Then collect all those value of buttons and student's id's and insert them in database.

 

I think I can collect student id's by doing this way:

 <?php
while ($row_st = mysql_fetch_assoc($students)){
    
$studentarray[] = $row_st['student_id'];
}
  foreach($studentarray as $value)
{ 
    


$sql_stu = "INSERT INTO attendanse (student_id, absense_id) VALUES ('$value', '$absens_id')";
mysql_query($sql_stu) OR die(mysql_error());

// The problem is How can I get value of buttons, value of absence_id. Please Help! // Don't forget to see attached image b/c
// one picture says 1000 words.
    
}
?>

post-133669-13482403477037_thumb.jpg

Link to comment
Share on other sites

Mahngiel: First of all, thank you for your response. I don't have deeply experience in development but I'am not either a very new beginner. I know litle about arrays, and chexboxes are not problem. I did a file upload function with multiple chekboxes that I could chose many classes(stil talking about student classes like Class 6A, 7A...) , and that function give every marked (chosen) class permision to see and oppen the file. I hope you understand what I mean. But When I want to wark with radio buttons .. I coudn't make it... they are make me out of my mind. To chose class and populate the students name generate from database to a table it wasn't difficult , but radio buttons.. the must have different name (every group must have different name.. as I understand) Maybe by doing FOR sats pr FOREACH sats.. so I realy apricate your help. Thank you again.

Link to comment
Share on other sites

Step 1) Get rid of a new form for every student

Step 2) Add the student's id to the radios

 '<input type="radio" name="attendance[$row['id']]" value="1">Accepted</input>'.  
    '<input type="radio" name="attendance[$row['id']]" value="2"> Not   accepted</input>'. 
    '<input type="radio" name="attendance[$row['id']]" value="3"> Tardy</input>'. 

Step 3) On form submit, catch and do whatever the hell you want.

Link to comment
Share on other sites

Thank you sir!

I tried like this:

<?php
if (isset($_REQUEST['submit']) && $_REQUEST['submit'] != "") {
if(isset($_POST['attendance'])) // Even tried  if(isset($_POST['attendance['.$row['student_id'].']'])) I don't know which one is correct
    {
        // I tried this one
        $absens_id = $_POST['attendance'];
        
        // and by this one 
        $absens_id = $_POST['attendance['.$row['student_id'].']'];
        //attendance['.$row['staff_id'].']
        
        for ($i=0; $i<sizeof($absens_id);$i++) {

$sql2 =	" INSERT INTO absence (absens_id ) ".
" VALUES ('".$absens_id[$i]."') ";
    mysql_query($sql2) or die(mysql_error());
}
}

}

?>
But I think the most problem is the hole form. Right now it's as following:

 

<?php
while($row = mysql_fetch_array($result))
  {
  print  '<tr>'.
  '<td>'.$row['firstname'].'</td>'.
  '<td>'. $row['lastname'] . '</td>'.
  '<td>'.
  '<form name="abs" method="POST" action="getuser.php" enctype="multipart/form-data">'.
//'<form action="getStudents.php" method="POST" >'.
'<input type="radio" name="attendance['.$row['student_id'].']" value="1">Accepted</input>'.      
'<input type="radio" name="attendance['.$row['student_id'].']" value="2">Not accepted</input>'.     
'<input type="radio" name="attendance['.$row['student_id'].']" value="3">Tardy</input>'. 
// If I put submit here then it gavs me submit button to every student. But I want one submit for all '<input type="submit" name="submit" value="Send">'.
'</td>'.
   
'</tr>';

  }
  // If I put submit button here with the same name then it didn't reacting no responding
  '<form name="abs" method="POST" action="getuser.php" enctype="multipart/form-data">'.
print '<input type="submit" name="submit" value="Send">'. 

'</form>'.
'<tr>'.
'<td>'.

'</td>'.

print '</table>';

?>

  I realy don't know how to correct it.

Link to comment
Share on other sites

 if (isset($_REQUEST['submit']) && $_REQUEST['submit'] != "") {

Not sure why you do this. I also think !empty($_REQUEST['submit']) would have done the same as isset and not equals "", unless you really want to check if it's not an empty string, in which case you must use !== instead of !=.

 

This is a good beginning:

if(isset($_POST['attendance']))

This is what you should do next I think:

foreach($_POST['attendance'] AS $key=>$value){
if($value == 2){
	echo $key . ' is not accepted';
}
}

I hope that makes any sense for you! :)

Link to comment
Share on other sites

My problem is now solved. Thank you very much for your help guys. You are wonderful people. Thank you now I will have a nice weekend. My form and getting value of radio buttons was totaly wrong. God bless you!

Link to comment
Share on other sites

  • 2 years later...

@mabrt001, it's not very likely that participants in a nearly three year old thread will see your post or even have the code that was developed. Asking for code is not really the point of programming help forums. We are here to help you with problems with code you have written. If you haven't written any code for your assignment or don't have any specific programming question, there's not much we can do for you.

 

if you do have some code you need help with or a programming question, please start you own thread for it.

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.