<?php
    require_once("../../php/db_utils.php");
    
    try {
        // Connect to the database
        $database = databaseConnect();
        
        // Incoming data
        $username = $_POST["username"];
        
        // Declare query
        $query = "SELECT tag FROM tags WHERE username = '" . $username . "' ORDER BY tag;";
        
        // Run query
        $recordSet = databaseQueryWithReturn($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
        databaseClose($database);
    }
    catch(Exception $e) {
        $errorMsg = $e->getMessage();
        print_r($errorMsg);
    }
?>