Files
memory-infrastructure-palace/docs/projects/memorypalace/Apple Notes/function postApplianceChange() {.md

4.5 KiB

$app = \Slim\Slim::getInstance(); $app->response()->header("Content-Type", "application/json"); $req = $app->request(); $reason = $req->params('reason'); $item = $req->params('item'); $pouchSKU = $req->params('pouchSKU'); $username = $req->params('username'); $bpSKU = $req->params('bpSKU'); //$req = $app->request(); //$body = json_decode($req->getBody());

if($item == "Pouch") { $sql=" INSERT INTO health_ostomy_appliance_change (ChangeDate, Reason, ItemsChanged, PouchSKU,DateEntered,WhoEntered ) VALUES (DATE_ADD(NOW(),INTERVAL 3 HOUR), :reason, :item, pouchSKU,DATE_ADD(NOW(),INTERVAL 3 HOUR), :username); INSERT INTO health_ostomy_stock (ProductSKU,ProductUnits, DateEntered,WhoEntered ) VALUES (:pouchSKU,-1,DATE_ADD(NOW(),INTERVAL 3 HOUR),:username); "; } else { $sql=" INSERT INTO health_ostomy_appliance_change (ChangeDate, Reason, ItemsChanged, BasePlateSKU, PouchSKU,DateEntered,WhoEntered ) VALUES (DATE_ADD(NOW(),INTERVAL 3 HOUR),:reason,:item,:bpSKU,:pouchSKU,DATE_ADD(NOW(),INTERVAL 3 HOUR),:username); INSERT INTO health_ostomy_stock (ProductSKU,ProductUnits, DateEntered,WhoEntered ) VALUES (:bpSKU,-1,DATE_ADD(NOW(),INTERVAL 3 HOUR),:username); INSERT INTO health_ostomy_stock (ProductSKU,ProductUnits, DateEntered,WhoEntered ) VALUES (:pouchSKU,-1,DATE_ADD(NOW(),INTERVAL 3 HOUR),:username); "; } echo $sql; try { $db = getConnection(); $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1); $stmt = $db->prepare($sql); $stmt->bindParam("reason", $reason); $stmt->bindParam("item", $item); $stmt->bindParam("pouchSKU", $pouchSKU); $stmt->bindParam("username", $username); $stmt->bindParam("bpSKU", $bpSKU); $result = $stmt->execute(); $dbCon = null;

  <span style="color:#000ff;">// check if row inserted or not</span>
  <span style="color:#000ff;">if ($result) {</span>
      <span style="color:#000ff;">// successfully inserted into database</span>
      <span style="color:#000ff;">$response["success"] = 1;</span>
      <span style="color:#000ff;">$response["message"] = "Rows inserted successfully.";</span>

      <span style="color:#000ff;">// echoing JSON response</span>
      <span style="color:#000ff;">echo json_encode($response);</span>
  <span style="color:#000ff;">} else {</span>
      <span style="color:#000ff;">// failed to insert row</span>
      <span style="color:#000ff;">$response["success"] = 0;</span>
      <span style="color:#000ff;">$response["message"] = "Bad news bears. Rows inserted unsuccessfully";</span>

      <span style="color:#000ff;">// echoing JSON response</span>
      <span style="color:#000ff;">echo json_encode($response);</span>
  <span style="color:#000ff;">}</span>

} catch(PDOException $e) { echo '{"error":{"text":'. $e->getMessage() .'}}'; } }