$value) { $requestStr .= $key . " : " . $value . "\n"; error_log($key . " : " . $value . "
\r\n"); } error_log("End Printing Request Attributes"); save_log($requestStr, 'Dispensary Stock', 'SAVE', 'stock_update.php'); $itemId = $_POST['stock_item_id']; echo $itemId; $stock_qty = $_POST['stock_qty']; $check_item = "select item_id from item_stock where item_id='" . $itemId . "' and ohc_type_id='" . $_SESSION['current_ohcttype'] . "' "; $check_items = mysqli_query($conn, $check_item); $row_check = @mysqli_num_rows($check_items); $query = ""; if ($row_check > 0) { $query = "update item_stock set stock_qty = '$stock_qty' where item_id='" . $itemId . "' and ohc_type_id='" . $_SESSION['current_ohcttype'] . "'"; } else { $query = "insert into item_stock set item_id = '$itemId',stock_qty = '$stock_qty' , ohc_type_id='" . $_SESSION['current_ohcttype'] . "'"; } if (!$result = @mysqli_query($conn, $query)) { error_log("Error saving Item stock" . mysqli_error($conn) . ". Error Query:" . $query); exit(mysqli_error($conn)); } ?> $total_quantity]); // } else { // echo json_encode(['error' => 'medicine_id not provided']); // } ?> prepare($query); $stmt->bind_param('i', $medicine_id); $stmt->execute(); $stmt->bind_result($stock_qty); if ($stmt->fetch()) { $stmt->close(); return $stock_qty; } else { $stmt->close(); return 0; } } if (isset($_POST['medicine_id'])) { $medicine_id = $_POST['medicine_id']; $total_quantity = get_total_quantity_by_medicine_id($medicine_id, $conn); echo json_encode(['total_quantity' => $total_quantity]); } else { echo json_encode(['error' => 'medicine_id not provided']); } //$conn->close(); ?>