Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jul 2012
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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.

  • #2
    New Coder
    Join Date
    Jul 2012
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts
    anyone for help?

  • #3
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,290
    Thanks
    23
    Thanked 611 Times in 610 Posts
    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.

  • Users who have thanked sunfighter for this post:

    havish (10-06-2012)

  • #4
    New Coder
    Join Date
    Jul 2012
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •