<?php
$qr_data = "QR code data"; // data from the QR code
$date = date('Y-m-d H:i:s'); // current date and time
// Connect to the database
$conn = new mysqli("hostname", "username", "password", "database_name");
// Insert the "in" scan data into the table
$sql = "INSERT INTO qr_codes (data, scanned_at, scan_type) VALUES ('$qr_data', '$date', 'in')";
$conn->query($sql);
// Close the connection
$conn->close();
?>
out
<?php
$qr_data = "QR code data"; // data from the QR code
$date = date('Y-m-d H:i:s'); // current date and time
// Connect to the database
$conn = new mysqli("hostname", "username", "password", "database_name");
// Insert the "out" scan data into the table
$sql = "INSERT INTO qr_codes (data, scanned_at, scan_type) VALUES ('$qr_data', '$date', 'out')";
$conn->query($sql);
// Close the connection
$conn->close();
?>
หรือ
2. insert+update (in/out ต่อ 1 record)
in
<?php
$qr_data = "QR code data"; // data from the QR code
$date = date('Y-m-d H:i:s'); // current date and time
// Connect to the database
$conn = new mysqli("hostname", "username", "password", "database_name");
// Insert the "in" scan data into the table
$sql = "INSERT INTO qr_codes (data, in_time) VALUES ('$qr_data', '$date')";
$conn->query($sql);
// Close the connection
$conn->close();
?>
out
<?php
$qr_data = "QR code data"; // data from the QR code
$date = date('Y-m-d H:i:s'); // current date and time
// Connect to the database
$conn = new mysqli("hostname", "username", "password", "database_name");
// Update the "out" scan data into the table
$sql = "UPDATE qr_codes SET out_time = '$date' WHERE data = '$qr_data'";
$conn->query($sql);
// Close the connection
$conn->close();
?>