<?php
include('../include/headscript.php');
include("../class/company.php");
$conn = new mysqli($servername, $username, $password, $database);

$analysisId = $_POST['analysis_id'] ?? null;
$compoundId = $_POST['compound_id'] ?? null;

if ($analysisId && $compoundId) {
    $sql = "INSERT INTO analysis_compounds (idanalysisvocabulary, idcompoundsvocabulary) VALUES (?, ?)";
    $stmt = $conn->prepare($sql);
    $stmt->bind_param("ii", $analysisId, $compoundId);

    if ($stmt->execute()) {
        echo json_encode(['success' => true]);
    } else {
        echo json_encode(['success' => false, 'error' => 'Error adding compound association.']);
    }

    $stmt->close();
} else {
    echo json_encode(['success' => false, 'error' => 'Invalid input data.']);
}

$conn->close();
