View file Remove image backgrounds/remove-bg/dark/admin-pannel/google_adsense_save.php

File size: 2Kb
<?php
// Include database configuration
require_once 'config/core.php';

// Check if the form was submitted
if (isset($_POST['save'])) {
    // Get the AdSense scripts from the form
    $adsenseScript1 = $_POST['adsense_script'];
    $adsenseScript2 = $_POST['adsense_script_1'];
    $adsenseScript3 = $_POST['adsense_script_2'];
    $adsenseScript4 = $_POST['adsense_script_3'];

    try {
        // Create PDO connection
        $pdo = new PDO("mysql:host=" . DB_HOST . ";dbname=" . DB_NAME, DB_USER, DB_PASS);
        $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

        // Check if there is an existing row in the table
        $sql = "SELECT COUNT(*) FROM google_adsense";
        $result = $pdo->query($sql);
        $rowCount = $result->fetchColumn();

        if ($rowCount > 0) {
            // If a row exists, update the scripts
            $stmt = $pdo->prepare("UPDATE google_adsense SET script = :script, script_1 = :script_1, script_2 = :script_2, script_3 = :script_3 WHERE id = 1");
            $stmt->execute([
                'script' => $adsenseScript1,
                'script_1' => $adsenseScript2,
                'script_2' => $adsenseScript3,
                'script_3' => $adsenseScript4
            ]);
        } else {
            // If no row exists, insert the scripts into the database
            $stmt = $pdo->prepare("INSERT INTO google_adsense (script, script_1, script_2, script_3) VALUES (:script, :script_1, :script_2, :script_3)");
            $stmt->execute([
                'script' => $adsenseScript1,
                'script_1' => $adsenseScript2,
                'script_2' => $adsenseScript3,
                'script_3' => $adsenseScript4
            ]);
        }

        // Redirect back to the google_adsense.php page
        header("Location: google_adsense.php");
        exit();
    } catch (PDOException $e) {
        // Handle database connection error
        echo "Connection failed: " . $e->getMessage();
    }
}
?>