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

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Retrieve data from the form
    $id = $_POST['id'];
    $profile = $_POST['profile'];
    $contact_person = $_POST['contact_person'];
    $designation = $_POST['designation'];
    $contact_number1 = $_POST['contact_number1'];
    $contact_email1 = $_POST['contact_email1'];
    $company_website1 = $_POST['company_website1'];
    $contact_number2 = $_POST['contact_number2'];
    $contact_email2 = $_POST['contact_email2'];
    $company_website2 = $_POST['company_website2'];
    $company_name = $_POST['company_name'];
    $linkedin_page = $_POST['linkedin_page'];
    $gmb_page = $_POST['gmb_page_username'];
    $gstin = $_POST['gstin'];
    $address = $_POST['address'];
    $city = $_POST['city'];
    $state = $_POST['state'];
    $zipcode = $_POST['zipcode'];
    $fb = $_POST['facebook_username'];
    $twitt = $_POST['twitter_username'];
    $insta = $_POST['instagram_username'];
    $youtube = $_POST['youtube_username'];

    // Define the vendor ID to update (you might need to retrieve this from the database)
    $vendor_id = 1; // Replace with the actual vendor ID

    // Update data in the database
    $sql = "UPDATE add_vendor 
            SET 
                profile = '$profile',
                contact_person = '$contact_person',
                designation = '$designation',
                contact_number1 = '$contact_number1',
                email1 = '$contact_email1',
                website1 = '$company_website1',
                contact_number2 = '$contact_number2',
                email2 = '$contact_email2',
                website2 = '$company_website2',
                company_name = '$company_name',
                linkedin_page = 'https://www.linkedin.com/in/$linkedin_page',
                gmb_page = 'https://www.google.com/$gmb_page',
                gstin = '$gstin',
                address = '$address',
                city = '$city',
                state = '$state',
                zipcode = '$zipcode',
                fb = 'https://www.facebook.com/$fb',
                twitt = 'https://twitter.com/$twitt',
                insta = 'https://www.instagram.com/$insta',
                youtube = 'https://www.youtube.com/$youtube'
                 WHERE id = $id";

    $result = mysqli_query($conn, $sql);

    // Check if the update was successful
    if ($result) {
        header("Location: b2b-all-vendor.php?success=Vendor 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);
    }
}
?>