check-if-tag-exists.php 941 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. require_once("../../php/db_utils.php");
  3. try {
  4. // Connect to the database
  5. $database = databaseConnect();
  6. // Incoming data
  7. $newTag = $_POST["tag"];
  8. $username = $_POST["username"];
  9. // Declare query
  10. $query = "SELECT tag FROM tags WHERE tag = '" . $newTag . "' AND username = '" . $username . "';";
  11. // Run query
  12. $recordSet = databaseQueryWithReturn($database, $query);
  13. // Get the tag if it exists, and return an empty string if it does not exist
  14. $record = mysqli_fetch_assoc($recordSet);
  15. $tag = $record["tag"];
  16. mysqli_free_result($recordSet);
  17. echo($tag);
  18. // Close the connection to the database
  19. databaseClose($database);
  20. }
  21. catch(Exception $e) {
  22. $errorMsg = $e->getMessage();
  23. print_r($errorMsg);
  24. }
  25. ?>