check-if-tag-exists.php 879 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. require_once("../../php/db_utils.php");
  3. try {
  4. // Connect to the database
  5. $database = db_connect();
  6. // Incoming data
  7. $newTag = $_POST["tag"];
  8. $canvasId = $_POST["canvas_id"];
  9. // Declare query
  10. $query = 'SELECT tag FROM tags WHERE tag = "' . $newTag . '" AND canvas_id = "' . $canvasId . '";';
  11. // Run query
  12. $recordSet = db_query_return($database, $query);
  13. // Return the tag if it exists
  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. db_close($database);
  20. }
  21. catch(Exception $e) {
  22. $errorMsg = $e->getMessage();
  23. print_r($errorMsg);
  24. }
  25. ?>