Attendance Management System in PHP and MySQL
We have a Form for submit the attendance
We will create a table for store the attendance records.
Now we are going to change in some fields of form.
We will convert all field in array format because name will be same of fields and value will be change and at a single time we are going to insert multiple record.
Now our HTML will look like this:
[html]
<form action="" method="post">
<table>
<tbody>
<tr>
<td>S.I</td>
<td>Roll No</td>
<td>Student Name</td>
<td>Attendance</td>
</tr>
<tr>
<td>1</td>
<td>
123
<input type="hidden" name="roll_no[]" value="123" />
</td>
<td>
Raj Shekhar
<input type="hidden" name="student_name[]" value="Raj Shekhar" />
</td>
<td>
<label for="present0">
<input type="radio" id="present0" name="attendance_status[0]" value="Present"> Present
</label>
<label for="absent0">
<input type="radio" id="absent0" name="attendance_status[0]" value="Absent"> Absent
</label>
</td>
</tr>
<tr>
<td>2</td>
<td>
231
<input type="hidden" name="roll_no[]" value="231" />
</td>
<td>
Pankaj Kumar
<input type="hidden" name="student_name[]" value="Pankaj Kumar" />
</td>
<td>
<label for="present1">
<input type="radio" id="present1" name="attendance_status[1]" value="Present"> Present
</label>
<label for="absent1">
<input type="radio" id="absent1" name="attendance_status[1]" value="Absent"> Absent
</label>
</td>
</tr>
<tr>
<td>3</td>
<td>
345
<input type="hidden" name="roll_no[]" value="345" />
</td>
<td>
Amit Singh
<input type="hidden" name="student_name[]" value="Amit Singh" />
</td>
<td>
<label for="present2">
<input type="radio" id="present2" name="attendance_status[2]" value="Present"> Present
</label>
<label for="absent2">
<input type="radio" id="absent2" name="attendance_status[2]" value="Absent"> Absent
</label>
</td>
</tr>
<tr>
<td>4</td>
<td>
456
<input type="hidden" name="roll_no[]" value="456" />
</td>
<td>
Arjun Kumar
<input type="hidden" name="student_name[]" value="Arjun Kumar" />
</td>
<td>
<label for="present3">
<input type="radio" id="present3" name="attendance_status[3]" value="Present"> Present
</label>
<label for="absent3">
<input type="radio" id="absent3" name="attendance_status[3]" value="Absent"> Absent
</label>
</td>
</tr>
<tr>
<td>5</td>
<td>
567
<input type="hidden" name="roll_no[]" value="567" />
</td>
<td>
Amit Kumar
<input type="hidden" name="student_name[]" value="Amit Kumar" />
</td>
<td>
<label for="present4">
<input type="radio" id="present4" name="attendance_status[4]" value="Present"> Present
</label>
<label for="absent4">
<input type="radio" id="absent4" name="attendance_status[4]" value="Absent"> Absent
</label>
</td>
</tr>
<tr>
<td>6</td>
<td>
789
<input type="hidden" name="roll_no[]" value="789" />
</td>
<td>
Suraj Tiwari
<input type="hidden" name="student_name[]" value="Suraj Tiwari" />
</td>
<td>
<label for="present5">
<input type="radio" id="present5" name="attendance_status[5]" value="Present"> Present
</label>
<label for="absent5">
<input type="radio" id="absent5" name="attendance_status[5]" value="Absent"> Absent
</label>
</td>
</tr>
</tbody>
</table>
<br/>
<input type="submit" name="submit" value="Mark Attendance" />
</form>
[/html]
I have create a static table. You can create a dynamic table and where I put number you can execute a counter in while or for loop.
And now we will write a code for insert the data.
[php]
if(isset($_POST[‘submit’]))
{
foreach ($_POST[‘attendance_status’] as $id => $attendance_status)
{
$roll_no = $_POST[‘roll_no’][$id];
$student_name = $_POST[‘student_name’][$id];
$date_created = date(‘Y-m-d H:i:s’);
$date_modified = date(‘Y-m-d H:i:s’);
$attendance = $conn->prepare("INSERT INTO attendance (roll_no, student_name, date_created, date_modified, attendance_status) VALUES (?, ?, ?, ?, ?)");
$attendance->bind_param("issss", $roll_no, $student_name, $date_created, $date_modified, $attendance_status);
$attendance->execute();
}
if ($conn->affected_rows==1) {
$msg = "Attendance has been added successfully";
}
}
[/php]
We can see the data has been successfully inserted
bala
how to create dependent dropdown list box in php only.?
vivek
how to create dynamic table with date and subject
pj
i need this project , for my project pls give source code and mysql db
ashraf
Thanks to you very much for such good work
How can I download the codes please
Thanks
admin
You can copy the code.
Roger
any idea how to use it or put the codes for laravel?
admin
This is for Core. Laravel is a PHP Framework and this code will not work you will have to find another tutorial for the same.
yashpathak21@gmail.com
this is just to put one day attendance , how can i post daily attendance ????
post it with add column feature in table every time when some one post attendance
admin
Hello Yash, You can add hidden variable for date. It is automatically fetch current date and store in database and second option you can add date input on form. When you will mark attendance firstly you will select date and then mark attendance as per student.
atinfotech
not insert data.
it gives ” Fatal error: Call to a member function bind_param() on boolean “
admin
Please check your table name and post variable. There is something wrong in this.
atinfotech
$servername = “localhost”;
$username = “root”;
$password = “”;
$dbname = “student”;
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die(“Connection failed: ” . $conn->connect_error);
}
Above is my connection and below table and coding as you given in tutorial
admin
Share your form and code screenshot as well. Because code is already tested
Sajid
Sir can u give me dynamic insert record ,source coe
admin
Hello Sajid,
I will publish it on our website and YouTube channel soon. For updates about more videos like this please subscribe our channel: https://www.youtube.com/WebsapexEcommerceWebDesignandWebDevelopmentCompany
Tushar
Great work sir…..your contribution saved many lives