$website, 'page_name' => $page_name, 'approval' => '1', ]; try { $ch = curl_init($url); curl_setopt_array($ch, [CURLOPT_POST => 1, CURLOPT_POSTFIELDS => $data, CURLOPT_RETURNTRANSFER => true]); $response = curl_exec($ch); if ($response === false) { throw new Exception(curl_error($ch)); } curl_close($ch); $resposneArray = json_decode($response, true); // Check if API response contains an error key if (isset($resposneArray['error'])) { throw new Exception($resposneArray['error']); } // Check if approval is 0 if ($resposneArray['approval'] == 0) { $sql = 'SELECT * FROM bckup_data WHERE page_name ="'.$page_name.'"'; $result = $conn->query($sql); $row = $result->fetch_assoc(); $title = $row['title']; $description = $row['description']; $h1 = $row['h1']; $h2 = $row['h2']; $form_heading = $row['form_heading']; $form_instruction = $row['form_instruction']; } else { // Use the data from the API response $title = $resposneArray['title']; $description = $resposneArray['description']; $h1 = $resposneArray['h1']; $h2 = $resposneArray['h2']; $form_heading = $resposneArray['form_heading']; $form_instruction = $resposneArray['form_instruction']; } } catch (Exception $e) { // Handle the exception (API error) by showing static data $sql = 'SELECT * FROM bckup_data WHERE page_name ="'.$page_name.'"'; $result = $conn->query($sql); $row = $result->fetch_assoc(); $title = $row['title']; $description = $row['description']; $h1 = $row['h1']; $h2 = $row['h2']; $form_heading = $row['form_heading']; $form_instruction = $row['form_instruction']; // You can also log or display the error message if needed error_log("API Error: " . $e->getMessage()); } ?>