View file Remove image backgrounds/remove-bg/dark/admin-pannel/update-contact-us.php

File size: 2.15Kb
<?php
   // Include your database connection configuration file
   require_once('config/core.php');
   
   // Check if the form data has been submitted
   if ($_SERVER["REQUEST_METHOD"] == "POST") {
       // Check if all required fields are present
       if (isset($_POST['id']) && isset($_POST['content']) && isset($_POST['script'])) {
           // Extract data from the form submission
           $id = $_POST['id'];
           $content = $_POST['content'];
           $script = $_POST['script'];
   
           // Establish database connection
           $conn = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
           if (!$conn) {
               die("Connection failed: " . mysqli_connect_error());
           }
   
           // Prepare SQL statement to update the content in the contact_us table
           $sql = "UPDATE contact_us SET content = ?, text = ? WHERE id = ?";
           $stmt = mysqli_prepare($conn, $sql);
           if ($stmt === false) {
               die("Error preparing statement: " . mysqli_error($conn));
           }
   
           // Bind parameters to the SQL statement
           mysqli_stmt_bind_param($stmt, "ssi", $content, $script, $id);
   
           // Execute the prepared statement
           if (mysqli_stmt_execute($stmt)) {
               // Content updated successfully
               mysqli_stmt_close($stmt);
               mysqli_close($conn);
               // Redirect to webpages-list.php
               header('Location: webpages-list.php');
               exit(); // Make sure to exit after redirection
               //echo "Data updated successfully"; // Response to indicate success
           } else {
               // Error occurred while executing the statement
               echo "Error updating data: " . mysqli_error($conn);
           }
   
           // Close the statement and connection
           mysqli_stmt_close($stmt);
           mysqli_close($conn);
       } else {
           // Required fields are missing
           echo "Missing required fields";
       }
   } else {
       // Request method is not POST
       echo "Invalid request method";
   }
   ?>