ถ้าจะทำระบบลงเวลาเข้ามาทำงาน ให้ลงเวลาเข้าได้ในช่วงก่อน 8:30 และลงเวลากลับได้ใน 16:30 เป็นต้นไป ต้องแก้ไข Code

ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา ถ้าจะทำระบบลงเวลาเข้ามาทำงาน ให้ลงเวลาเข้าได้ในช่วงก่อน 8:30 และลงเวลากลับได้ใน 16:30 เป็นต้นไป ต้องแก้ไข Code

ถ้าจะทำระบบลงเวลาเข้ามาทำงาน ให้ลงเวลาเข้าได้ในช่วงก่อน 8:30 และลงเวลากลับได้ใน 16:30 เป็นต้นไป ต้องแก้ไข Code
ถ้าจะทำระบบลงเวลาเข้ามาทำงาน ให้ลงเวลาเข้าได้ในช่วงก่อน 8:30 และลงเวลากลับได้ใน 16:30 เป็นต้นไป ต้องแก้ไข Code อย่างไรครับ

ชุดไฟล์ + Code ทั้งหมดครับ

1. 
dbtest.sql (ชื่อ database คือ dbtest ครับ)


CREATE TABLE `dbtest` (
  `IDrun` int(100) COLLATE utf8_unicode_ci NOT NULL AUTO_INCREMENT,
  `IDnumber` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
  `Name` longtext COLLATE utf8_unicode_ci NOT NULL,
  `MyTime` longtext COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY  (`IDrun`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

2. add.php

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
* {
  font-size: 3vw;
}
</style>
</head>
<body>

<?php
date_default_timezone_set("Asia/Bangkok");
$timestamp = time();
$thaiyear = date('Y') + 543;
?>

<center><h2>Time Attendance</h2>

<form action="save.php" name="frmAdd" method="post">
<table width="284" border="1">
  <tr>
    <th width="120">IDnumber</th>
    <td width="238"><input type="text" name="txtCustomerID" size="14"></td>
    </tr>
  <tr>
    <th width="120">Name</th>
    <td><input type="text" name="txtName" size="14"></td>
    </tr>
  <tr>
    <th width="120">Time</th>
    <td><input type="hidden" name="txtEmail" size="14" value="<?php echo(date("d-m-$thaiyear H:i:s", $timestamp));?>"><?php echo(date("d-m-$thaiyear H:i:s", $timestamp));?></td>
  </tr>
  </table><br>
  <input type="submit" name="submit" value="Full Submit"> 
</form></center>

</body>
</html>

3. save.php

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="refresh" content="3;url=add.php">
</head>
<body>
<?php
	ini_set('display_errors', 1);
	error_reporting(~0);

	$serverName = "localhost";
	$userName = "root";
	$userPassword = "";
	$dbName = "dbtest";

	$conn = mysqli_connect($serverName,$userName,$userPassword,$dbName);
	mysqli_set_charset($conn, "utf8");
	
	$sql = "INSERT INTO dbtest (IDnumber, Name, MyTime)
	VALUES ('".$_POST["txtCustomerID"]."','".$_POST["txtName"]."','".$_POST["txtEmail"]."')";

	$query = mysqli_query($conn,$sql);
	
	if($query) {
		echo "ลงเวลาเข้ามาทำงานแล้ว";
	}

	mysqli_close($conn);
?>
</body>
</html>

Screenshot ครับ



Sumate Mephokkij 159.192.221.xxx 28-03-2020 14:49:54

คำแนะนำ และการใช้งาน

สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก


  • ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
  • เปลี่ยน


    ( หรือ เข้าใช้งานผ่าน Social Login )

 ความคิดเห็นที่ 1
สร้างเงื่อนไขเวลา ก่อนและหลัง ที่ต้องการ ถึงจะทำการเพิ่มข้อมูลได้
if(เงื่อนไขก่อน และ เงื่อนไขไขหลัง){
/// ลงเวลาได้
}else{
//  ลงเวลาไม่ได้
}
 
ดูเกี่ยวกับการใช้งาน strtotime() เป็นแนวทาง


บทความแนะนำที่เกี่ยวข้อง
การใช้งานรูปแบบข้อความวันที่และเวลา กับฟังก์ชั่น strtotime() ใน phpอ่าน 53,848
ninenik 223.24.167.xxx 28-03-2020
 ความคิดเห็นที่ 2
ขอบคุณครับ สำหรับคำตอบ Code ใช้งานได้แล้ว ซึ่งปรับปรุงเป็นฉบับของตัวเอง ซึ่งรวมถึงรองรับ Responsive Font ได้ดังนี้ครับ

1. workathome.sql (ชื่อ database คือ workathome ครับ)

CREATE TABLE `workathome` (
  `IDrun` int(100) COLLATE utf8_unicode_ci NOT NULL AUTO_INCREMENT,
  `IDnumber` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
  `Name` longtext COLLATE utf8_unicode_ci NOT NULL,
  `MyTime` longtext COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY  (`IDrun`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

2. add.php

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="UTF-8">
<style>
* {
  font-size: 3vw;
}
</style>
</head>
<body>

<?php
date_default_timezone_set("Asia/Bangkok");
$timestamp = time();
$thaiyear = date('Y') + 543;
?>

<center><h2>Time Attendance</h2>

<form action="save.php" name="frmAdd" method="post">
<table width="284" border="1">
  <tr>
    <th width="120">IDnumber</th>
    <td width="238"><input type="text" name="txtCustomerID" size="14"></td>
    </tr>
  <tr>
    <th width="120">Name</th>
    <td><input type="text" name="txtName" size="14"></td>
    </tr>
  <tr>
    <th width="120">Time</th>
    <td><input type="hidden" name="txtEmail" size="14" value="<?php echo(date("d-m-$thaiyear H:i:s", $timestamp));?>"><?php echo(date("d-m-$thaiyear H:i:s", $timestamp));?></td>
  </tr>
  </table><br>
  <input type="submit" name="submit" value="Full Submit">
</form></center>

</body>
</html>

3. save.php

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="refresh" content="3;url=add.php">
<meta charset="UTF-8">
<style>
* {
  font-size: 3vw;
}
</style>
</head>
<body>
<center>
<?php
	ini_set('display_errors', 1);
	error_reporting(~0);

	$serverName = "localhost";
	$userName = "root";
	$userPassword = "";
	$dbName = "workathome";

	$conn = mysqli_connect($serverName,$userName,$userPassword,$dbName);
	mysqli_set_charset($conn, "utf8");
	
	date_default_timezone_set("Asia/Bangkok");

	$ThatTime ="08:30:00";
	$ThatTime2 ="16:30:00";
	if (time() > strtotime($ThatTime) && time() < strtotime($ThatTime2)) {
		// ลงเวลาไม่ได้
		echo "หมดเวลา ลงเวลามาทำงานแล้ว";
	}else {
		//  ลงเวลาได้
		$sql = "INSERT INTO workathome (IDnumber, Name, MyTime)
		VALUES ('".$_POST["txtCustomerID"]."','".$_POST["txtName"]."','".$_POST["txtEmail"]."')";

		$query = mysqli_query($conn,$sql);
		echo "ลงเวลามาทำงานแล้ว";
	}
	mysqli_close($conn);
?>
</center>
</body>
</html>

Screenshot ครับ



Sumate Mephokkij 159.192.218.xxx 29-03-2020 13:17






เว็บไซต์ของเราให้บริการเนื้อหาบทความสำหรับนักพัฒนา โดยพึ่งพารายได้เล็กน้อยจากการแสดงโฆษณา โปรดสนับสนุนเว็บไซต์ของเราด้วยการปิดการใช้งานตัวปิดกั้นโฆษณา (Disable Ads Blocker) ขอบคุณครับ