<?php
    require_once("../../php/db_utils.php");
    
    try {
        // Connect to the database
        $database = db_connect();
        
        // Incoming data
        $canvasId = $_POST["canvas_id"];
        
        // Declare query
        $query = "SELECT tag FROM tags WHERE canvas_id = '" . $canvasId . "' ORDER BY tag;";
        
        // Run query
        $recordSet = db_query_return($database, $query);
        
        // Get tags by active user
        $tags = Array();
        
        while($record = $recordSet->fetch_assoc()) {
            $tags[] = $record["tag"];
        }
        
        mysqli_free_result($recordSet);
        
        echo(json_encode($tags));
        
        // Close the connection to the database
        db_close($database);
    }
    catch(Exception $e) {
        $errorMsg = $e->getMessage();
        print_r($errorMsg);
    }
?>