tabalinas / jsgrid

Lightweight Grid jQuery Plugin
http://js-grid.com
MIT License
1.53k stars 353 forks source link

Help with a php & Mysql #1428

Open RicardoSemDedao opened 11 months ago

RicardoSemDedao commented 11 months ago

Hello Team,

I want to express my gratitude for providing us with this excellent grid. It has proven to be extremely user-friendly and efficient to work with. Great job on creating such a useful tool!

I must admit that I'm not a professional programmer, and my experience mostly revolves around small projects for work or immediate necessities. Occasionally, I encounter more complex projects, but they are rare for me. Due to my limited experience, it's possible that the solution to my current problem might be right in front of me, but I could be overlooking it.

With that in mind, I apologize if my question seems obvious or I fail to recognize a straightforward solution. I greatly appreciate your patience and support as I seek to resolve my issue. Thank you for your understanding.

I'm having problems saving my updates or adding new records in the database.

Here is the grid code: ?php require_once('includes/load.php');

// Checking what level user has permission to view this page page_require_level(2);

// Header HTML include_once('layouts/header.php');

// Fetch data from the database table (limit to 40 records) $db = new MySqli_DB(); $sql = "SELECT * FROM commodity"; $result = $db->query($sql); $records = $db->while_loop($result);

? ?php // Enable error reporting error_reporting(E_ALL);

// Display errors on the screen ini_set('display_errors', 1); ? <!DOCTYPE html>

Commodity

php include_once('layouts/footer.php');

Here is the database action

php var_dump($_REQUEST); header("Content-Type: application/json"); header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE"); header("Access-Control-Allow-Headers: Access-Control-Allow-Headers,Content-Type,Access-Control-Allow-Methods, Authorization, X-Requested-With");

ini_set('display_errors', 'On'); error_reporting(E_ALL);

try { require_once('includes/load.php');

$input = json_decode(file_get_contents('php://input'),true);
var_dump($input); // Print out data you receive

switch ($_SERVER["REQUEST_METHOD"]) {
    case "GET":
        $result = $db->query("SELECT * FROM commodity");
        header("Content-Type: application/json");
        echo json_encode($db->while_loop($result));
        break;

    case "POST":
        $db->query("INSERT INTO commodity (part_number, haz_un_number, Description, HazPckGroup, HazClass, Hazmat, PackageType, Size, NetWt, Weight, Hazard_INHALATION, Molecule)
            VALUES ('{$input['part_number']}', '{$input['haz_un_number']}', '{$input['Description']}', '{$input['HazPckGroup']}', '{$input['HazClass']}', '{$input['Hazmat']}', '{$input['PackageType']}', '{$input['Size']}', {$input['NetWt']}, {$input['Weight']}, '{$input['Hazard_INHALATION']}', '{$input['Molecule']}')");
        header("Content-Type: application/json");
        echo json_encode($input);
        break;

    case "PUT":
        $db->query("UPDATE commodity SET part_number = '{$input['part_number']}', haz_un_number = '{$input['haz_un_number']}', Description = '{$input['Description']}', HazPckGroup = '{$input['HazPckGroup']}', HazClass = '{$input['HazClass']}', Hazmat = '{$input['Hazmat']}', PackageType = '{$input['PackageType']}', Size = '{$input['Size']}', NetWt = {$input['NetWt']}, Weight = {$input['Weight']}, Hazard_INHALATION = '{$input['Hazard_INHALATION']}', Molecule = '{$input['Molecule']}' WHERE ID = {$input['ID']}");
        header("Content-Type: application/json");
        echo json_encode($input);
        break;

    case "DELETE":
        $db->query("DELETE FROM commodity WHERE ID = {$input['ID']}");
        header("Content-Type: application/json");
        echo json_encode($input);
        break;
}

} catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; }