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

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Retrieve form data
    $name = $_POST["name"];
    $companyName = $_POST["company_name"];
    $contact1 = $_POST["contact1"];
    $contact2 = $_POST["contact2"];
    $email1 = $_POST["email1"];
    $email2 = $_POST["email2"];
    $website1 = $_POST["website1"];
    $website2 = $_POST["website2"];
    // $linkedinPage = $_POST["linkedin_page"];
    $linkedin_username = mysqli_real_escape_string($conn, $_POST['linkedin_username']);
    $linkedinFollowers = $_POST["linkedin_followers"];
    // $gmbPage = $_POST["gmb_page"];
    $gmb_page_username = mysqli_real_escape_string($conn, $_POST['gmb_page_username']);
    $gmbReview = $_POST["gmb_review"];
    $facebook_username = mysqli_real_escape_string($conn, $_POST['facebook_username']);
    // $fbUrl = $_POST["fb_url"];
    $fbReview = $_POST["fb_review"];
    $instagram_username = mysqli_real_escape_string($conn, $_POST['instagram_username']);
    // $instaUrl = $_POST["insta_url"];
    $instaReview = $_POST["insta_review"];
    // $twittUrl = $_POST["twitt_url"];
    $twitter_username = mysqli_real_escape_string($conn, $_POST['twitter_username']);
    $twittReview = $_POST["twitt_review"];
    // $youtubeUrl = $_POST["youtube_url"];
    $youtube_username = mysqli_real_escape_string($conn, $_POST['youtube_username']);
    $youtubeReview = $_POST["youtube_review"];

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

    $service = $_POST["service"];
    $source = $_POST["source"];
    $leadDate = $_POST["lead_date"];
    $leadDescription = $_POST["lead_discription"];
    $currentDateTime = date('Y-m-d H:i:s');


    $sql = "INSERT INTO add_leads(name, company_name, contact1, contact2, email1, email2, website1, website2, linkedin_page, linkedin_followers, gmb_page, gmb_review, fb_url, fb_review, insta_url, insta_review, twitt_url, twitt_review, youtube_url, youtube_review, whatsapp_url,whatsapp_review, service, source, lead_date, lead_discription,datetime)
            VALUES('$name', '$companyName', '$contact1', '$contact2', '$email1', '$email2', '$website1', '$website2', 'https://www.linkedin.com/in/$linkedin_username', '$linkedinFollowers', 'https://www.google.com/$gmb_page_username', '$gmbReview', 'https://www.facebook.com/$facebook_username', '$fbReview',  'https://www.instagram.com/$instagram_username', '$instaReview', 'https://twitter.com/$twitter_username', '$twittReview','https://www.youtube.com/$youtube_username', '$youtubeReview','https://wa.me/+ $whatsapp_username','$whatsappReview', '$service', '$source', '$leadDate', '$leadDescription','$currentDateTime')";

    if (mysqli_query($conn, $sql)) {

        // echo "Lead added successfully";
     header("Location: add-leads.php?success=Lead Added Successfully!!!");
     exit();

    } else {
        echo "Error: " . $sql . "<br>" . mysqli_error($conn);
    }

    mysqli_close($conn);
}
?>