<?php
include('connection.php');

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Retrieve data from the form
    $id = $_POST['id'];
    $name = $_POST['name'];
    $add = $_POST['add'];
    $number1 = $_POST['number1'];
    $number2 = $_POST['number2'];
    $number3 = $_POST['number3'];
    $company_name = $_POST['company_name'];
    $gmb_page = $_POST['gmb_page_username'];
    $fb = $_POST['facebook_username'];
    $twitt = $_POST['twitter_username'];
    $insta = $_POST['instagram_username'];
    $youtube = $_POST['youtube_username'];

    // Update data in the database
    $sql = "UPDATE add_contact 
            SET    name='$name', purpose_to_add='$add', number1='$number1', number2='$number2', number3='$number3',
            company_name='$company_name', gmb_page='https://www.google.com/$gmb_page', fb='https://www.facebook.com/$fb', twitter='https://twitter.com/$twitt', insta='https://www.instagram.com/$insta', youtube='https://www.youtube.com/$youtube'
            WHERE id=$id";
            
    $result = mysqli_query($conn, $sql);

    // Execute the statement
    if ($result) {
        
        header("Location: view-all-contacts.php?success=Contact Updated Successfully!!!");
        exit(); // Exit to prevent further script execution

    } else {
        // Handle update failure (display an error message or redirect to an error page)
        echo "Error: " . mysqli_error($conn);
    }
}
?>