Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-06-2012, 07:37 AM   PM User | #1
havish
New Coder

 
Join Date: Jul 2012
Posts: 26
Thanks: 1
Thanked 0 Times in 0 Posts
havish is an unknown quantity at this point
Smile Checkbox values to database

I am trying to develop a attendance management system.. I have one master table of students which contains details like student name, roll no, class and so on.. Here is my form for registering the students. I have a connection to database already.
[html]<form id="form1" name="form1" method="post" action="process.php">
<fieldset>
<legend>Student Registration Form</legend>
<p>Student Name:
<label for="stud_name"></label>
<input type="text" name="stud_name" id="stud_name" />
</p>
<p>Student Roll No:
<label for="stud_roll"></label>
<input type="text" name="stud_roll" id="stud_roll" />
</p>
<p>Class:
<label for="stud_class"></label>
<input type="text" name="stud_class" id="stud_class" />
</p>
<p>Contact Number:
<label for="stud_contact"></label>
<input type="text" name="stud_contact" id="stud_contact" />
</p>
<p>Father's Name:
<label for="stud_father"></label>
<input type="text" name="stud_father" id="stud_father" />
</p>
<p>Mother's Name:
<label for="stud_mother"></label>
<input type="text" name="stud_mother" id="stud_mother" />
</p>
<p>Parent Contact Number:
<label for="stud_parent_contact"></label>
<input type="text" name="stud_parent_contact" id="stud_parent_contact" />
</p>
<p>Address:
<label for="stud_address"></label>
<input type="text" name="stud_address" id="stud_address" />
</p>

<p>
<input type="submit" name="submit" id="submit" value="Submit" />
</p>
</fieldset>

</form>[/html]
and now process.php and id is primary key.
PHP Code:
if(isset($_POST['submit']))
{
$studname $_POST['stud_name'];
$studroll $_POST['stud_roll'];
$studclass $_POST['stud_class'];
$studcontact $_POST['stud_contact'];
$studfather $_POST['stud_father'];
$studmother $_POST['stud_mother'];
$studparentcontact $_POST['stud_parent_contact'];
$studaddress $_POST['stud_address'];
$query "INSERT INTO `student`(`id`, `studname`, `studroll`, `studclass`, `studcontact`, `studfather`, `studmother`, `studparentcontact`, `studaddress`, `addedon`) VALUES (NULL,'$studname','$studroll','$studclass','$studcontact','$studfather','$studmother','$studparentcontact','$studaddress',CURRENT_TIMESTAMP)";    
$result mysql_query($query);

}
if(
$result)
{
 echo
"done";    
}
else
{
echo
"no";    
}

?> 
so after inserting some values, my database looks like this


Now I need to take attendance of particular class, say 5th. For this I need to pull out data from the student table for the student's name. For this I have att.php file
PHP Code:
$report mysql_query("SELECT id, studname, studroll FROM student WHERE studclass = 5  ") or die(mysql_error()); 
[html]<form action="process1.php" method="post">
<table width="567" border="1">
<tr>
<th width="83" scope="col">ID</th>
<th width="83" scope="col">Student Name</th>
<th width="55" scope="col">Student Roll.No</th>
<th width="51" scope="col">Present</th>
<th width="68" scope="col">Absent</th>
<th width="276" scope="col">Remarks of Absentees</th>
</tr>[/html]
PHP Code:
while($info mysql_fetch_array($report))
  { 
[html]<tr>
<td>[/html]
PHP Code:
echo $info['id']; 
[html]</td>
<td>[/html]
PHP Code:
echo $info['studname']; 
[html]</td>
<td>[/html]
PHP Code:
echo $info['studroll']; 
[html]</td>

<td align="center"><input type="checkbox" name="pre[]" id="pre" value="P" />
<label for="pre"></label></td>
<td align="center"><input type="checkbox" name="abs[]" id="abs" value="A" />
<label for="abs"></label></td>
<td align="center"><label for="remarks"></label>
<input type="text" name="remarks" id="remarks" /></td>
</tr>[/html]
PHP Code:
}
  echo 
"</table>"
[html]<input type="submit" name="submit" id="submit" value="Submit" />
</form>[/html]
And I have a table in database for attendance. So when I mark the attendance through selecting the checkbox, the value should get inserted in the database with the same id as in the student table(master table). I have established a foreign key in the attendance table and below are the images




This is what i did till now. Now my doubt is when i click submit in att.php the details should get updated in attendance table with corresponding id's of the respective students. I hope you got the point. My intention is in whicever table data gets updated it should be with the id of the student. When i check the checkbox of all students and click submit the data should go into attendance table. For this i have tried with foreach loop
PHP Code:
foreach($present as $p
where
PHP Code:
$present $_POST['pre']; 
and same for absent. Now i am stuck with database part. how do i update or insert data into attendance table. Kindly help..

Last edited by havish; 10-06-2012 at 08:17 AM..
havish is offline   Reply With Quote
Old 10-06-2012, 03:13 PM   PM User | #2
havish
New Coder

 
Join Date: Jul 2012
Posts: 26
Thanks: 1
Thanked 0 Times in 0 Posts
havish is an unknown quantity at this point
anyone for help?
havish is offline   Reply With Quote
Old 10-06-2012, 03:15 PM   PM User | #3
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,396
Thanks: 18
Thanked 352 Times in 351 Posts
sunfighter is on a distinguished road
This is just my humble opinion on your attendance table not the final word at all, but please consider this:

You need three tables, one for each class you teach. Your present table is missing the most important column = the date of the class your taken attendance on. It is also carrying too much information. The table should assume all students are present except the ones in the table. So the table needs three column. a) the students ID number, b) the date and c) remarks or call it excuse or the reason for the absence.
sunfighter is offline   Reply With Quote
Users who have thanked sunfighter for this post:
havish (10-06-2012)
Old 10-06-2012, 08:47 PM   PM User | #4
havish
New Coder

 
Join Date: Jul 2012
Posts: 26
Thanks: 1
Thanked 0 Times in 0 Posts
havish is an unknown quantity at this point
Quote:
Originally Posted by sunfighter View Post
This is just my humble opinion on your attendance table not the final word at all, but please consider this:

You need three tables, one for each class you teach. Your present table is missing the most important column = the date of the class your taken attendance on. It is also carrying too much information. The table should assume all students are present except the ones in the table. So the table needs three column. a) the students ID number, b) the date and c) remarks or call it excuse or the reason for the absence.
Thanks for the suggestion
havish is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:01 PM.


Advertisement
Log in to turn off these ads.