From e8698e360f2c9030471e427e75260520b4eb9160 Mon Sep 17 00:00:00 2001 From: sctn4elk Date: Fri, 3 May 2024 19:27:12 -0500 Subject: [PATCH] Continue work on insert --- Controller/API/CustomerController.php | 10 +++++----- Model/CustomerModel.php | 15 ++++++++------- Model/Database.php | 4 ++-- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Controller/API/CustomerController.php b/Controller/API/CustomerController.php index 155d4a1..923d217 100644 --- a/Controller/API/CustomerController.php +++ b/Controller/API/CustomerController.php @@ -119,13 +119,13 @@ class CustomerController extends BaseController{ // reads the raw POST data and returns it as a string. $jsonPayload = file_get_contents('php://input'); $input = json_decode($jsonPayload, TRUE); - //if (! $this->validatePerson($input)) { - //return $this->unprocessableEntityResponse(); - //} - return var_dump($input); + if (! $this->validatePerson($input)) { + return $this->unprocessableEntityResponse(); + } + //return var_dump($input); //remove customer_id field so it doesn't break unset($input['customer_id']); - return var_dump($input); + //return var_dump($input); //$modinput = json_encode($input); //$newinput = json_decode($modinput, TRUE); $response = $this->customerModel->insertCustomer($input); diff --git a/Model/CustomerModel.php b/Model/CustomerModel.php index ee4c790..0a5aa3a 100644 --- a/Model/CustomerModel.php +++ b/Model/CustomerModel.php @@ -86,18 +86,19 @@ class CustomerModel extends Database { return $this->processQuery("SELECT * FROM customer_view WHERE customer_id = ?", ["i", $this->customerId]); } - public function insertCustomer($jsonPayLoad) + public function insertCustomer($inputModel) { //return var_dump($jsonPayLoad); - $keys = array_keys($jsonPayLoad); + $keys = array_keys($inputModel); $n = count($keys); - $query .= "CALL insert_new_customer_proc ('" . $jsonPayLoad[$keys[0]] . "', "; - for($i = 1; $i < $n-1; $i++) { - $query .= "'" . $jsonPayLoad[$keys[$i]] . "', "; + $query .= "CALL insert_new_customer_proc ("; + for($i = 0; $i < $n-1; $i++) { + $query .= "'" . $inputModel[$keys[$i]] . "', "; } - $query .= $jsonPayLoad[$keys[$i]] . ")"; - return var_dump($query); + $query .= $inputModel[$keys[$i]] . ")"; + //return var_dump($query); + $rowCount = $this->processStatement($query); return $rowCount; } diff --git a/Model/Database.php b/Model/Database.php index ba394a1..ca6be17 100644 --- a/Model/Database.php +++ b/Model/Database.php @@ -65,10 +65,10 @@ class Database { if($stmt === false) { throw New Exception("Unable to prepare the statement: " . $query); } - + //return var_dump($query); $result = $stmt->execute(); if($result === false) { - throw New Exception("Unable to execute the statement."); + throw New Exception("Unable to execute the statement: " . $query); } //$rowCount = $this->executeStatement($stmt);