52 lines
1.4 KiB
PHP
52 lines
1.4 KiB
PHP
<?php
|
|
session_start();
|
|
include '../config.php';
|
|
|
|
// Disable error reporting untuk output
|
|
error_reporting(0);
|
|
ini_set('display_errors', 0);
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
if (!isset($_SESSION['id_pembeli'])) {
|
|
echo json_encode(['success' => false, 'message' => 'Akses ditolak']);
|
|
exit;
|
|
}
|
|
|
|
// Get JSON data
|
|
$data = json_decode(file_get_contents('php://input'), true);
|
|
$alamat = isset($data['alamat']) ? trim($data['alamat']) : '';
|
|
|
|
if (empty($alamat)) {
|
|
echo json_encode(['success' => false, 'message' => 'Alamat tidak boleh kosong']);
|
|
exit;
|
|
}
|
|
|
|
$id_pembeli = intval($_SESSION['id_pembeli']);
|
|
|
|
// Update address in database
|
|
$query = mysqli_prepare($conn, "UPDATE pembeli SET alamat = ? WHERE id_pembeli = ?");
|
|
mysqli_stmt_bind_param($query, "si", $alamat, $id_pembeli);
|
|
|
|
if (mysqli_stmt_execute($query)) {
|
|
// Get updated pembeli data
|
|
$query_pembeli = mysqli_query($conn, "SELECT * FROM pembeli WHERE id_pembeli = '$id_pembeli'");
|
|
$pembeli = mysqli_fetch_assoc($query_pembeli);
|
|
|
|
echo json_encode([
|
|
'success' => true,
|
|
'message' => 'Alamat berhasil diperbarui',
|
|
'data' => [
|
|
'alamat' => $pembeli['alamat']
|
|
]
|
|
]);
|
|
} else {
|
|
echo json_encode([
|
|
'success' => false,
|
|
'message' => 'Gagal memperbarui alamat: ' . mysqli_error($conn)
|
|
]);
|
|
}
|
|
|
|
mysqli_stmt_close($query);
|
|
mysqli_close($conn);
|
|
?>
|