...

View Full Version : Checkbox values to database



havish
10-06-2012, 07:37 AM
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.

<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>
and now process.php and id is primary key.

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','$studparentco ntact','$studaddress',CURRENT_TIMESTAMP)";
$result = mysql_query($query);

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

?>
so after inserting some values, my database looks like this
http://imageshack.us/a/img442/4145/databased.jpg (http://imageshack.us/photo/my-images/442/databased.jpg/)

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

$report = mysql_query("SELECT id, studname, studroll FROM student WHERE studclass = 5 ") or die(mysql_error());


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

while($info = mysql_fetch_array($report))
{

<tr>
<td>
echo $info['id'];
</td>
<td>
echo $info['studname'];
</td>
<td>
echo $info['studroll'];
</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>
}
echo "</table>";
<input type="submit" name="submit" id="submit" value="Submit" />
</form>
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
http://imageshack.us/a/img850/7887/foreign.jpg (http://imageshack.us/photo/my-images/850/foreign.jpg/)

http://imageshack.us/a/img4/3871/attim.jpg (http://imageshack.us/photo/my-images/4/attim.jpg/)

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

foreach($present as $p) where
$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..

havish
10-06-2012, 03:13 PM
anyone for help?

sunfighter
10-06-2012, 03:15 PM
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.

havish
10-06-2012, 08:47 PM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum