%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/public_html/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
|--------------------------------------------------------------------------
*/
$address_id = intval(
$_REQUEST['address_id']
?? $json['address_id']
?? 0
);
$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($address_id) ||
empty($full_name) ||
empty($flat_house) ||
empty($street_name) ||
empty($address)
) {
response(false, "Required fields missing", [
"required_fields" => [
"address_id",
"full_name",
"flat_house",
"street_name",
"address"
],
"example_url" =>
BASE_URL .
"api/update_address.php?address_id=1&full_name=Siddharth%20Jha&flat_house=Flat%20101&street_name=MG%20Road&address=Paris%20France&is_primary=1",
"sample_request" => [
"address_id" => 1,
"full_name" => "Siddharth Jha",
"flat_house" => "Flat 101",
"street_name" => "MG Road",
"address" => "Paris France",
"is_primary" => 1
],
"postman_form_data" => [
[
"key" => "address_id",
"value" => "1"
],
[
"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" => [
"address_id" => 1,
"full_name" => "Siddharth Jha",
"flat_house" => "Flat 101",
"street_name" => "MG Road",
"address" => "Paris France",
"is_primary" => 1
],
"received_data" => [
"request" => $_REQUEST,
"json" => $json
]
]);
}
/*
|--------------------------------------------------------------------------
| Check Address Exists
|--------------------------------------------------------------------------
*/
$check = mysqli_query(
$conn,
"SELECT *
FROM user_address
WHERE id='$address_id'
AND user_id='$user_id'"
);
if (mysqli_num_rows($check) == 0) {
response(false, "Address not found", [
"address_id" => $address_id,
"suggestion" =>
"Please send valid address_id"
]);
}
/*
|--------------------------------------------------------------------------
| Primary Address Logic
|--------------------------------------------------------------------------
*/
if ($is_primary == 1) {
mysqli_query(
$conn,
"UPDATE user_address
SET is_primary=0
WHERE user_id='$user_id'"
);
}
/*
|--------------------------------------------------------------------------
| Update Address
|--------------------------------------------------------------------------
*/
$update = mysqli_query(
$conn,
"UPDATE user_address SET
full_name='$full_name',
flat_house='$flat_house',
street_name='$street_name',
address='$address',
is_primary='$is_primary'
WHERE id='$address_id'
AND user_id='$user_id'"
);
if ($update) {
response(true, "Address Updated Successfully", [
"address_id" => $address_id,
"updated_address" => [
"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"
]
]);
}
response(false, "Update Failed", [
"mysql_error" => mysqli_error($conn)
]);
$conn->close();
?>