prepare("SELECT * FROM road_challans WHERE id = ?"); $stmt->bind_param("i", $id); $stmt->execute(); $result = $stmt->get_result(); if ($result->num_rows === 0) { echo "Record not found."; exit; } $challan = $result->fetch_assoc(); $d_vehicle_date = $challan['d_vehicle_date']; // echo $d_vehicle_date; // die(); // Handle form submission if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Escape string values $bill_book_vendor = $conn->real_escape_string($_POST['bill_book_vendor'] ?? ''); $bill_book_invoice = $conn->real_escape_string($_POST['bill_book_invoice'] ?? ''); $bill_book_date = $conn->real_escape_string($_POST['bill_book_date'] ?? ''); $bill_book_vehicle_type = $conn->real_escape_string($_POST['bill_book_vehicle_type'] ?? ''); $d_vehicle_date = $conn->real_escape_string($_POST['d_vehicle_date'] ?? ''); $date_of_reach = $conn->real_escape_string($_POST['date_of_reach'] ?? ''); $days_diff = (int)($_POST['days_diff'] ?? 0); $updated_at = date('Y-m-d H:i:s'); // Escape and format date_of_unloading $date_raw = $_POST['date_of_unloading'] ?? ''; $formatted_date = $date_raw ? date('Y-m-d H:i:s', strtotime($date_raw)) : null; $date_of_unloading = $formatted_date ? "'" . $conn->real_escape_string($formatted_date) . "'" : "NULL"; // Numeric values function get_numeric_or_null($value) { return is_numeric($value) ? $value : 'NULL'; } $bill_book_value = get_numeric_or_null($_POST['bill_book_value'] ?? null); $bill_book_loading_expenses = get_numeric_or_null($_POST['bill_book_loading_expenses'] ?? null); $bill_book_office_expenses = get_numeric_or_null($_POST['bill_book_office_expenses'] ?? null); $bill_book_total_cost = get_numeric_or_null($_POST['bill_book_total_cost'] ?? null); $bill_book_lease_exp = get_numeric_or_null($_POST['bill_book_lease_exp'] ?? null); $bill_book_fuel_exp = get_numeric_or_null($_POST['bill_book_fuel_exp'] ?? null); $bill_book_toll_exp = get_numeric_or_null($_POST['bill_book_toll_exp'] ?? null); $bill_book_freight_exp = get_numeric_or_null($_POST['bill_book_freight_exp'] ?? null); $bill_book_road_exp = get_numeric_or_null($_POST['bill_book_road_exp'] ?? null); $bill_book_total_exp = get_numeric_or_null($_POST['bill_book_total_exp'] ?? null); // Build SQL $sql = "UPDATE `road_challans` SET `bill_book_vendor` = '$bill_book_vendor', `bill_book_invoice` = '$bill_book_invoice', `bill_book_date` = '$bill_book_date', `bill_book_value` = $bill_book_value, `bill_book_loading_expenses` = $bill_book_loading_expenses, `bill_book_office_expenses` = $bill_book_office_expenses, `bill_book_total_cost` = $bill_book_total_cost, `bill_book_vehicle_type` = '$bill_book_vehicle_type', `bill_book_lease_exp` = $bill_book_lease_exp, `bill_book_fuel_exp` = $bill_book_fuel_exp, `bill_book_toll_exp` = $bill_book_toll_exp, `bill_book_freight_exp` = $bill_book_freight_exp, `bill_book_road_exp` = $bill_book_road_exp, `bill_book_total_exp` = $bill_book_total_exp, `d_vehicle_date` = '$d_vehicle_date', `date_of_reach` = '$date_of_reach', `date_of_unloading` = $date_of_unloading, `days_diff` = $days_diff, `updated_at` = '$updated_at' WHERE `id` = $id"; // Debug option // echo $sql; exit; if ($conn->query($sql) === TRUE) { echo ""; } else { echo "Error updating record: " . $conn->error; } exit; } require_once('includes/header.php'); ?>