return $row; } function count_stock($post_type_id) { $sql = "SELECT COUNT(*) AS rows FROM tbl_product_stock WHERE `type_id` = '{$post_type_id}'"; $query = $this->conn->query($sql); $result = $query->fetch_object(); return $result; } function update($post_stock_quantity, $post_stock_id) { $sql = "UPDATE tbl_product_stock SET `stock_quantity` = ? WHERE `stock_id` = ?"; $stmt = $this->conn->prepare($sql); if ($stmt === false) { trigger_error('Database error: ' . $sql . ' Error: ' . $this->conn->errno . ' ' . $this->conn->error, E_USER_ERROR); } else { $stmt->bind_param("ss", $post_stock_quantity, $post_stock_id); $stmt->execute(); } $stmt->close(); } } $_ajax = new AJAX(); $ajx_type_id = $_POST['type']; $ajx_stock_qty = $_POST['value']; $ajx_stock_id = $_POST['id']; foreach ($ajx_stock_id as $key => $stock_id) { filter_var($stock_id, FILTER_SANITIZE_STRING); $_ajax->update($ajx_stock_qty[$key], $stock_id); } }