%PDF- %GIF98; %PNG;
Server : ApacheSystem : Linux sh00666.bluehost.com 5.14.0-687.26.1.el9_8.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Jul 14 16:32:02 EDT 2026 x86_64 User : ndkhermy ( 1200) PHP Version : 8.5.12 Disable Function : NONE Directory : /home1/ndkhermy/www/website_6ca89795/api/ |
Upload File : |
<?php
header("Content-Type: application/json");
include("../dbcon.php");
include("auth.php");
define('BASE_URL', 'https://meatandgo.fr/');
function response($status, $message, $data = [])
{
echo json_encode([
"status" => $status,
"message" => $message,
"data" => $data
], JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
exit;
}
/*
|--------------------------------------------------------------------------
| Support Form Data + Raw JSON
|--------------------------------------------------------------------------
*/
$json = json_decode(file_get_contents("php://input"), true);
/*
|--------------------------------------------------------------------------
| Receive Data
|--------------------------------------------------------------------------
*/
$full_name = trim(
$_REQUEST['full_name']
?? $json['full_name']
?? ''
);
$flat_house = trim(
$_REQUEST['flat_house']
?? $json['flat_house']
?? ''
);
$street_name = trim(
$_REQUEST['street_name']
?? $json['street_name']
?? ''
);
$address = trim(
$_REQUEST['address']
?? $json['address']
?? ''
);
$is_primary = intval(
$_REQUEST['is_primary']
?? $json['is_primary']
?? 0
);
/*
|--------------------------------------------------------------------------
| Validation
|--------------------------------------------------------------------------
*/
if (
empty($full_name) ||
empty($flat_house) ||
empty($street_name) ||
empty($address)
) {
response(false, "Required fields missing", [
"required_fields" => [
"full_name",
"flat_house",
"street_name",
"address"
],
"example_url" =>
BASE_URL .
"api/save_address.php?full_name=Siddharth%20Jha&flat_house=Flat%20101&street_name=MG%20Road&address=Paris%20France&is_primary=1",
"sample_request" => [
"full_name" => "Siddharth Jha",
"flat_house" => "Flat 101",
"street_name" => "MG Road",
"address" => "Paris France",
"is_primary" => 1
],
"postman_form_data" => [
[
"key" => "full_name",
"value" => "Siddharth Jha"
],
[
"key" => "flat_house",
"value" => "Flat 101"
],
[
"key" => "street_name",
"value" => "MG Road"
],
[
"key" => "address",
"value" => "Paris France"
],
[
"key" => "is_primary",
"value" => "1"
]
],
"raw_json_example" => [
"full_name" => "Siddharth Jha",
"flat_house" => "Flat 101",
"street_name" => "MG Road",
"address" => "Paris France",
"is_primary" => 1
],
"received_data" => [
"request" => $_REQUEST,
"json" => $json
]
]);
}
/*
|--------------------------------------------------------------------------
| Primary Address Logic
|--------------------------------------------------------------------------
*/
if ($is_primary == 1) {
mysqli_query(
$conn,
"UPDATE user_address
SET is_primary=0
WHERE user_id='$user_id'"
);
}
/*
|--------------------------------------------------------------------------
| Insert Address
|--------------------------------------------------------------------------
*/
$stmt = $conn->prepare("
INSERT INTO user_address
(
user_id,
full_name,
flat_house,
street_name,
address,
is_primary
)
VALUES
(
?, ?, ?, ?, ?, ?
)
");
$stmt->bind_param(
"issssi",
$user_id,
$full_name,
$flat_house,
$street_name,
$address,
$is_primary
);
if ($stmt->execute()) {
response(true, "Address Saved Successfully", [
"address_id" => $conn->insert_id,
"saved_address" => [
"user_id" => $user_id,
"full_name" => $full_name,
"flat_house" => $flat_house,
"street_name" => $street_name,
"address" => $address,
"is_primary" => $is_primary
],
"next_api" => [
"address_list_api" =>
BASE_URL . "api/address_list.php"
]
]);
} else {
response(false, "Address Save Failed", [
"mysql_error" => $stmt->error
]);
}
$stmt->close();
$conn->close();
?>