File: C:/xampp/htdocs/myapi/postTestap.php
<?php
// Get the JSON data sent from the client
$json = file_get_contents('php://input');
// Decode JSON to PHP array
$data = json_decode($json, true);
$dtime=time();
$dStr=substr($dtime,7,9)."-";
// Process the data
if ($data !== null) {
// Access the JSON values
$name = $data['name'];
$age = $data['age'];
$email = $data['email'];
$myFile =$dStr."-api.txt";
$fvcc = fopen($myFile, 'w') or die("can't open file");
fwrite($fvcc, $name."\n");
fwrite($fvcc, $age."\n");
fwrite($fvcc, $email."\n");
fclose($fvcc);
// Perform actions with the data (e.g., save to a database, perform operations, etc.)
// Example: Insert data into a database
// Your database connection code here...
// $mysqli = new mysqli("localhost", "username", "password", "database");
// $query = "INSERT INTO your_table_name (name, age, email) VALUES ('$name', '$age', '$email')";
// $mysqli->query($query);
// Respond back to the client (optional)
echo json_encode(array('message' => 'Data received and processed successfully'));
} else {
// Respond with an error message if JSON data is invalid
echo json_encode(array('message' => 'Invalid JSON data'));
}
?>