Created
December 29, 2024 19:53
-
-
Save elico/ab0c80245f3db6d99c87d51acdb653a8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
header('Content-Type: application/json'); | |
$data = json_decode(file_get_contents('php://input'), true); | |
// Extract date and time from the request | |
$date = $data['date']; // Assuming date is in 'Y-m-d' format (e.g., '2024-07-05') | |
$time = $data['time']; // Assuming time is in 'H:i:s' format (e.g., '15:30:00') | |
// Combine date and time into a timestamp | |
$timestamp = strtotime("$date $time"); | |
// Create a connection to your MariaDB database | |
$servername = "your_hostname"; | |
$username = "your_username"; | |
$password = "your_password"; | |
$dbname = "your_database_name"; | |
$conn = new mysqli($servername, $username, $password, $dbname); | |
// Check connection | |
if ($conn->connect_error) { | |
die("Connection failed: " . $conn->connect_error); | |
} | |
// Prepare and execute the SQL statement | |
$sql = "INSERT INTO your_table_name (your_column_name, timestamp_column) | |
VALUES ('your_value', FROM_UNIXTIME($timestamp))"; | |
if ($conn->query($sql) === TRUE) { | |
$response = array('status' => 'success', 'message' => 'Data inserted successfully'); | |
} else { | |
$response = array('status' => 'error', 'message' => "Error: " . $conn->error); | |
} | |
$conn->close(); | |
echo json_encode($response); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment