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

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $id = $_POST["id"];
    $name = $_POST["name"];
    $company_name = $_POST["company_name"];
    $contact1 = $_POST["contact1"];
    $contact2 = $_POST["contact2"];
    $email1 = $_POST["email1"];
    $email2 = $_POST["email2"];
    $website1 = $_POST["website1"];
    $website2 = $_POST["website2"];
    // $linkedin_page = $_POST["linkedin_page"];
    $linkedin_username = mysqli_real_escape_string($conn, $_POST['linkedin_username']);
    $linkedin_followers = $_POST["linkedin_followers"];
    // $gmb_page = $_POST["gmb_page"];
    $gmb_page_username = mysqli_real_escape_string($conn, $_POST['gmb_page_username']);
    $gmb_review = $_POST["gmb_review"];
    // $fb_url = $_POST["fb_url"];
    $facebook_username = mysqli_real_escape_string($conn, $_POST['facebook_username']);
    $fb_review = $_POST["fb_review"];
    // $insta_url = $_POST["insta_url"];
    $instagram_username = mysqli_real_escape_string($conn, $_POST['instagram_username']);
    $insta_review = $_POST["insta_review"];
    // $twitt_url = $_POST["twitt_url"];
    $twitter_username = mysqli_real_escape_string($conn, $_POST['twitter_username']);
    $twitt_review = $_POST["twitt_review"];
    // $youtube_url = $_POST["youtube_url"];
    $youtube_username = mysqli_real_escape_string($conn, $_POST['youtube_username']);
    $youtube_review = $_POST["youtube_review"];

    $whatsapp_username = mysqli_real_escape_string($conn, $_POST['whatsapp_username']);
    $whatsapp_review = $_POST["whatsapp_review"];

    $service = $_POST["service"];
    $source = $_POST["source"];
    $lead_date = $_POST["lead_date"];
    $lead_discription = $_POST["lead_discription"];

    // Update the lead in the database
    $updateSql = "UPDATE add_leads SET
        name = '$name',
        company_name = '$company_name',
        contact1 = '$contact1',
        contact2 = '$contact2',
        email1 = '$email1',
        email2 = '$email2',
        website1 = '$website1',
        website2 = '$website2',
        linkedin_page = '$linkedin_username',
        linkedin_followers = '$linkedin_followers',
        gmb_page = '$gmb_page_username',
        gmb_review = '$gmb_review',
        fb_url = ' $facebook_username',
        fb_review = '$fb_review',
        insta_url = '$instagram_username',
        insta_review = '$insta_review',
        twitt_url = '$twitter_username',
        twitt_review = '$twitt_review',
        youtube_url = '$youtube_username',
        youtube_review = '$youtube_review',
        whatsapp_url = '$whatsapp_username',
        whatsapp_review = '$whatsapp_review',
        service = '$service',
        source = '$source',
        lead_date = '$lead_date',
        lead_discription = '$lead_discription'
    WHERE id = $id";

    if (mysqli_query($conn, $updateSql)) {
        header("Location: view-all-leads.php?success=Lead Updated Successfully");
        exit();
    } else {
        echo "Error updating lead: " . mysqli_error($conn);
    }
}
?>