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

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Retrieve data from the form
    $profile = mysqli_real_escape_string($conn, $_POST['profile']);
    $contact_person = mysqli_real_escape_string($conn, $_POST['contact_person']);
    $designation = mysqli_real_escape_string($conn, $_POST['designation']);
    $contact_number1 = mysqli_real_escape_string($conn, $_POST['contact_number1']);
    $contact_email1 = mysqli_real_escape_string($conn, $_POST['contact_email1']);
    $company_website1 = mysqli_real_escape_string($conn, $_POST['company_website1']);
    $contact_number2 = mysqli_real_escape_string($conn, $_POST['contact_number2']);
    $contact_email2 = mysqli_real_escape_string($conn, $_POST['contact_email2']);
    $company_website2 = mysqli_real_escape_string($conn, $_POST['company_website2']);
    $company_name = mysqli_real_escape_string($conn, $_POST['company_name']);
    $linkedin_username = mysqli_real_escape_string($conn, $_POST['linkedin_username']);
    $gmb_page_username = mysqli_real_escape_string($conn, $_POST['gmb_page_username']);

    $gstin = mysqli_real_escape_string($conn, $_POST['gstin']);
    $address = mysqli_real_escape_string($conn, $_POST['address']);
    $city = mysqli_real_escape_string($conn, $_POST['city']);
    $state = mysqli_real_escape_string($conn, $_POST['state']);
    $zipcode = mysqli_real_escape_string($conn, $_POST['zipcode']);
    $facebook_username = mysqli_real_escape_string($conn, $_POST['facebook_username']);
    $twitter_username = mysqli_real_escape_string($conn, $_POST['twitter_username']);
    $instagram_username = mysqli_real_escape_string($conn, $_POST['instagram_username']);
    $youtube_username = mysqli_real_escape_string($conn, $_POST['youtube_username']);
    $currentDateTime = date('Y-m-d H:i:s');

    // Insert data into the database
    $sql = "INSERT INTO add_vendor (profile, contact_person, designation, contact_number1, email1, website1, contact_number2, email2, website2, company_name, linkedin_page, gmb_page, gstin, address, city, state, zipcode, fb, twitt, insta, youtube, datetime) 
            VALUES ('$profile', '$contact_person', '$designation', '$contact_number1', '$contact_email1', '$company_website1', '$contact_number2', '$contact_email2', '$company_website2', '$company_name', 'https://www.linkedin.com/in/$linkedin_username', 'https://www.google.com/$gmb_page_username', '$gstin', '$address', '$city', '$state', '$zipcode', 'https://www.facebook.com/$facebook_username', 'https://twitter.com/$twitter_username', 'https://www.instagram.com/$instagram_username', 'https://www.youtube.com/$youtube_username', '$currentDateTime')";
            
    $result = mysqli_query($conn, $sql);

    // Execute the statement
    if ($result) {
        header("Location: b2b-add-vendor.php?success=Vendor Added Successfully!!!");
        exit(); // Exit to prevent further script execution

    } else {
        header("Location: b2b-add-vendor.php?error=Failed insertion!!!");
        exit(); // Exit to prevent further script execution
    }
}
?>