<?php
    require_once("../../php/db_utils.php");
    
    try {
        // Connect to the database
        $database = databaseConnect();
        
        // Incoming data
        $newTag = $_POST["tag"];
        $username = $_POST["username"];
        
        // Declare query
        $query = "SELECT tag FROM tags WHERE tag = '" . $newTag . "' AND username = '" . $username . "';";
        
        // Run query
        $recordSet = databaseQueryWithReturn($database, $query);
        
        // Get the tag if it exists, and return an empty string if it does not exist
        $record = mysqli_fetch_assoc($recordSet);
        
        $tag = $record["tag"];
        
        mysqli_free_result($recordSet);
        
        echo($tag);
        
        // Close the connection to the database
        databaseClose($database);
    }
    catch(Exception $e) {
        $errorMsg = $e->getMessage();
        print_r($errorMsg);
    }
?>