check-comments.php 1022 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. require_once("../../php/db_utils.php");
  3. try {
  4. // Connect to the database
  5. $database = db_connect();
  6. // Incoming data
  7. $canvasId = $_POST["canvas_id"];
  8. $ideaId = $_POST["idea_id"];
  9. // Declare query
  10. $query = 'SELECT id
  11. FROM comments
  12. WHERE canvas_id = "' . $canvasId . '"
  13. AND idea_id = "' . $ideaId . '";';
  14. // Run query
  15. $recordSet = db_query_return($database, $query);
  16. // Get comments by active user
  17. $comments = Array();
  18. while($record = $recordSet->fetch_assoc()) {
  19. $comments[] = $record["id"];
  20. }
  21. mysqli_free_result($recordSet);
  22. echo(json_encode($comments));
  23. // Close the connection to the database
  24. db_close($database);
  25. }
  26. catch(Exception $e) {
  27. $errorMsg = $e->getMessage();
  28. print_r($errorMsg);
  29. }
  30. ?>