แจกตัวอย่างโปรแกรมเช็คชื่อ เพื่อเอาไปเป็นแนวทางและต่อยอด รองรับการทำงานบน PHP v.7 – 8 . ฐานข้อมูลใช้ MySQL
แจกให้ศึกษาและพัฒนาต่อยอดเท่านั้น ห้ามนำไปใช้งานจริง
โปรโมชั่นพิเศษ ลดสูงสุด 80%!
ขาย Source Code พร้อมใช้งาน นำไปต่อยอดได้ทันที
ดูสินค้าทั้งหมด ได้ที่ : https://devbanban.com/?p=4425
ซื้อแล้วปรึกษาได้ตลอด
สนใจติดต่อ inbox ที่แฟนเพจ
☎️ โทร: 094-861-6709
Line OA : https://lin.ee/v8VwivgC
- รวมคลิปสอน PHP PDO MySQL (ฟรีคอร์ส) เข้าเรียน คลิก
- รวมคลิปสอน Laravel v.12 (ฟรีคอร์ส) เข้าเรียน คลิก
ภาพการทำงาน

0. database
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
-- phpMyAdmin SQL Dump -- version 5.2.1 -- https://www.phpmyadmin.net/ -- -- Host: localhost -- Generation Time: May 01, 2026 at 06:20 AM -- Server version: 10.4.28-MariaDB -- PHP Version: 8.1.17 SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; START TRANSACTION; SET time_zone = "+00:00"; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8mb4 */; -- -- Database: `project_attendance` -- CREATE DATABASE IF NOT EXISTS `project_attendance` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; USE `project_attendance`; -- -------------------------------------------------------- -- -- Table structure for table `attendance` -- CREATE TABLE `attendance` ( `id` int(11) NOT NULL, `student_id` int(11) DEFAULT NULL, `status` enum('present','absent','leave','late') DEFAULT 'absent', `date` date DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -- -- Dumping data for table `attendance` -- INSERT INTO `attendance` (`id`, `student_id`, `status`, `date`) VALUES (4, 1, 'present', '2026-05-01'), (5, 2, 'absent', '2026-05-01'), (6, 3, 'leave', '2026-05-01'), (7, 4, 'late', '2026-05-01'); -- -------------------------------------------------------- -- -- Table structure for table `students` -- CREATE TABLE `students` ( `id` int(11) NOT NULL, `student_code` varchar(20) DEFAULT NULL, `first_name` varchar(100) DEFAULT NULL, `last_name` varchar(100) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -- -- Dumping data for table `students` -- INSERT INTO `students` (`id`, `student_code`, `first_name`, `last_name`) VALUES (1, '111', '111', '111'), (2, '222', '222', '222'), (3, '333', '333', '333'), (4, '444', '444', '444'); -- -- Indexes for dumped tables -- -- -- Indexes for table `attendance` -- ALTER TABLE `attendance` ADD PRIMARY KEY (`id`), ADD KEY `student_id` (`student_id`); -- -- Indexes for table `students` -- ALTER TABLE `students` ADD PRIMARY KEY (`id`), ADD UNIQUE KEY `student_code` (`student_code`); -- -- AUTO_INCREMENT for dumped tables -- -- -- AUTO_INCREMENT for table `attendance` -- ALTER TABLE `attendance` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=8; -- -- AUTO_INCREMENT for table `students` -- ALTER TABLE `students` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5; -- -- Constraints for dumped tables -- -- -- Constraints for table `attendance` -- ALTER TABLE `attendance` ADD CONSTRAINT `attendance_ibfk_1` FOREIGN KEY (`student_id`) REFERENCES `students` (`id`); COMMIT; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; |
1. index.php
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
<!DOCTYPE html> <html lang="th"> <head> <meta charset="UTF-8"> <title>ระบบเช็คชื่อ</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> </head> <body class="bg-light"> <div class="container mt-5 text-center"> <h2 class="mb-4">📋 ระบบเช็คชื่อ</h2> <a href="add_student.php" class="btn btn-primary m-2">➕ เพิ่มนักเรียน</a> <a href="attendance.php" class="btn btn-success m-2">✅ เช็คชื่อ</a> <a href="report.php" class="btn btn-dark m-2">📊 รายงาน</a> </div> </body> </html> |
2. config.php
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<?php $host = "localhost"; $db = "project_attendance"; $user = "root"; $pass = ""; try { $pdo = new PDO("mysql:host=$host;dbname=$db;charset=utf8", $user, $pass); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { echo "เชื่อมต่อไม่สำเร็จ: " . $e->getMessage(); } ?> |
3. add_student.php
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
<?php include 'config.php'; ?> <!DOCTYPE html> <html lang="th"> <head> <meta charset="UTF-8"> <title>เพิ่มนักเรียน</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> </head> <body class="bg-light"> <div class="container mt-5"> <div class="card col-md-6 mx-auto shadow"> <div class="card-header bg-primary text-white"> ➕ เพิ่มนักเรียน </div> <div class="card-body"> <form method="post"> <div class="mb-3"> <label class="form-label">รหัสนักศึกษา</label> <input type="text" name="student_code" class="form-control" required> </div> <div class="mb-3"> <label class="form-label">ชื่อ</label> <input type="text" name="first_name" class="form-control" required> </div> <div class="mb-3"> <label class="form-label">นามสกุล</label> <input type="text" name="last_name" class="form-control" required> </div> <button class="btn btn-success w-100">💾 บันทึก</button> </form> <?php if ($_POST) { try { $stmt = $pdo->prepare(" INSERT INTO students (student_code, first_name, last_name) VALUES (?, ?, ?) "); $stmt->execute([ $_POST['student_code'], $_POST['first_name'], $_POST['last_name'] ]); echo '<div class="alert alert-success mt-3">เพิ่มเรียบร้อย</div>'; } catch (PDOException $e) { echo '<div class="alert alert-danger mt-3">รหัสนักศึกษาซ้ำ!</div>'; } } ?> </div> </div> </div> </body> </html> |
4. attendance.php
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
<?php include 'config.php'; ?> <!DOCTYPE html> <html lang="th"> <head> <meta charset="UTF-8"> <title>เช็คชื่อ</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> </head> <body class="bg-light"> <div class="container mt-4"> <div class="card shadow"> <div class="card-header bg-success text-white"> เช็คชื่อประจำวัน </div> <div class="card-body"> <form method="post"> <table class="table table-bordered align-middle"> <thead class="table-dark"> <tr> <th>รหัส</th> <th>ชื่อ - นามสกุล</th> <th class="text-center">สถานะ</th> </tr> </thead> <tbody> <?php $stmt = $pdo->query("SELECT * FROM students ORDER BY student_code ASC"); while ($row = $stmt->fetch()) { $id = $row['id']; ?> <tr> <td><?= $row['student_code'] ?></td> <td> <?= $row['first_name'] ?> <?= $row['last_name'] ?> </td> <td> <div class="d-flex justify-content-center gap-2 flex-wrap"> <label class="form-check"> <input type="radio" name="status[<?= $id ?>]" value="present" class="form-check-input" checked> <span class="text-success">มา</span> </label> <label class="form-check"> <input type="radio" name="status[<?= $id ?>]" value="absent" class="form-check-input"> <span class="text-danger">ขาด</span> </label> <label class="form-check"> <input type="radio" name="status[<?= $id ?>]" value="leave" class="form-check-input"> <span class="text-warning">ลา</span> </label> <label class="form-check"> <input type="radio" name="status[<?= $id ?>]" value="late" class="form-check-input"> <span class="text-info">มาสาย</span> </label> </div> </td> </tr> <?php } ?> </tbody> </table> <button class="btn btn-primary w-100">💾 บันทึก</button> </form> <?php if ($_POST) { $date = date('Y-m-d'); // ลบข้อมูลวันเดิม $pdo->prepare("DELETE FROM attendance WHERE date=?")->execute([$date]); $values = []; $params = []; foreach ($_POST['status'] as $student_id => $status) { $values[] = "(?, ?, ?)"; array_push($params, $student_id, $status, $date); } // insert หลายแถวในครั้งเดียว $sql = "INSERT INTO attendance (student_id, status, date) VALUES " . implode(",", $values); $stmt = $pdo->prepare($sql); $stmt->execute($params); echo '<div class="alert alert-success mt-3">บันทึกเรียบร้อย</div>'; } ?> </div> </div> </div> </body> </html> |
5. report.php
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
<?php include 'config.php'; ?> <!DOCTYPE html> <html lang="th"> <head> <meta charset="UTF-8"> <title>รายงานการเข้าเรียน</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> </head> <body class="bg-light"> <div class="container mt-4"> <div class="card shadow"> <div class="card-header bg-dark text-white"> 📊 รายงานการเข้าเรียน </div> <div class="card-body"> <?php // 📥 ดึงข้อมูลใหม่ (รองรับชื่อ-นามสกุล + รหัส) $sql = "SELECT s.student_code, s.first_name, s.last_name, a.status, a.date FROM attendance a JOIN students s ON a.student_id = s.id ORDER BY a.date DESC"; $data = $pdo->query($sql)->fetchAll(); // 🔢 summary $summary = [ 'present' => 0, 'absent' => 0, 'leave' => 0, 'late' => 0 ]; foreach ($data as $row) { if (isset($summary[$row['status']])) { $summary[$row['status']]++; } } ?> <!-- 🔥 Summary --> <div class="row text-center mb-4"> <div class="col"> <div class="card bg-success text-white"> <div class="card-body"> มา<br><h4><?= $summary['present'] ?></h4> </div> </div> </div> <div class="col"> <div class="card bg-danger text-white"> <div class="card-body"> ขาด<br><h4><?= $summary['absent'] ?></h4> </div> </div> </div> <div class="col"> <div class="card bg-warning text-dark"> <div class="card-body"> ลา<br><h4><?= $summary['leave'] ?></h4> </div> </div> </div> <div class="col"> <div class="card bg-info text-dark"> <div class="card-body"> มาสาย<br><h4><?= $summary['late'] ?></h4> </div> </div> </div> </div> <!-- 📋 ตาราง --> <table class="table table-bordered table-striped align-middle"> <thead class="table-secondary"> <tr> <th>รหัส</th> <th>ชื่อ - นามสกุล</th> <th>สถานะ</th> <th>วันที่</th> </tr> </thead> <tbody> <?php foreach ($data as $row): // 🎨 สีสถานะ switch ($row['status']) { case 'present': $status = '<span class="badge bg-success">มา</span>'; break; case 'absent': $status = '<span class="badge bg-danger">ขาด</span>'; break; case 'leave': $status = '<span class="badge bg-warning text-dark">ลา</span>'; break; case 'late': $status = '<span class="badge bg-info text-dark">มาสาย</span>'; break; } ?> <tr> <td><?= $row['student_code'] ?></td> <td> <?= $row['first_name'] ?> <?= $row['last_name'] ?> </td> <td><?= $status ?></td> <td><?= $row['date'] ?></td> </tr> <?php endforeach; ?> </tbody> </table> </div> </div> </div> </body> </html> |
ลองเอาไปต่อยอดดูนะครับ
ร่วมสนับสนุน ค่ากาแฟ ค่าโฮส devbanban.com ได้ที่
ธนาคารกรุงไทย
ชื่อบัญชี นายพิศิษฐ์ บวรเลิศสุธี เลขที่ 878-0-17747-6
————————————————————————————
ธนาคารไทยพาณิชย์
ชื่อบัญชี นายพิศิษฐ์ บวรเลิศสุธี เลขที่ 406-359094-1
————————————————————————————
ธนาคารกสิกร
ชื่อบัญชี นายพิศิษฐ์ บวรเลิศสุธี เลขที่ 048-1-17571-2
fanpage : https://www.facebook.com/sornwebsites/