post-comment.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. $collaborator = $_POST["collaborator"];
  9. $ideaId = $_POST["idea_id"];
  10. $comment = $_POST["comment"];
  11. // Set the date
  12. $date = date("Y-m-d H:i:s", strtotime("-3607 second"));
  13. // Add new comment with the description
  14. $query = 'INSERT INTO comments (canvas_id, collaborator, date, idea_id, comment) VALUES ("' . $canvasId . '", "' . $collaborator . '", "' . $date . '", "' . $ideaId . '", "' . $comment . '");';
  15. // Insert new or update old description
  16. db_query_no_return($database, $query);
  17. // Declare query
  18. $query = 'SELECT comments.id, user.name
  19. FROM comments
  20. INNER JOIN user ON comments.collaborator = user.username
  21. WHERE comments.collaborator = "' . $collaborator . '"
  22. AND comments.date = "' . $date . '";';
  23. // Run query
  24. $recordSet = db_query_return($database, $query);
  25. // Declarations
  26. $returnData = Array();
  27. // Get the records
  28. $record = $recordSet->fetch_assoc();
  29. // Remember the records
  30. $returnData[] = $record["id"];
  31. $returnData[] = $record["name"];
  32. $returnData[] = $date;
  33. mysqli_free_result($recordSet);
  34. echo(json_encode($returnData));
  35. // Close the connection to the database
  36. db_close($database);
  37. }
  38. catch(Exception $e) {
  39. $errorMsg = $e->getMessage();
  40. print_r($errorMsg);
  41. }
  42. ?>