<?php
    require_once("../../php/db_utils.php");
    
    try {
        // Connect to the database
        $database = db_connect();
        
        // Incoming data
        $tag = $_POST["tag"];
        $canvasId = $_POST["canvas_id"];
        
        // Declare query
        $query = "SELECT description FROM tags WHERE tag = '" . $tag . "' AND canvas_id = '" . $canvasId . "';";
        
        // Run query
        $recordSet = db_query_return($database, $query);
        
        // Get description for the selected tag
        $record = mysqli_fetch_assoc($recordSet);
        
        $description = $record["description"];
        
        mysqli_free_result($recordSet);
        
        echo($description);
        
        // Close the connection to the database
        db_close($database);
    }
    catch(Exception $e) {
        $errorMsg = $e->getMessage();
        print_r($errorMsg);
    }
?>