12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <?php
- require_once("../../php/db_utils.php");
-
- try {
- // Connect to the database
- $database = db_connect();
-
- // Incoming data
- $canvasId = $_POST["canvas_id"];
- $collaborator = $_POST["collaborator"];
- $ideaId = $_POST["idea_id"];
- $comment = $_POST["comment"];
-
- // Set the date
- $date = date("Y-m-d H:i:s", strtotime("-3607 second"));
-
- // Add new comment with the description
- $query = 'INSERT INTO comments (canvas_id, collaborator, date, idea_id, comment) VALUES ("' . $canvasId . '", "' . $collaborator . '", "' . $date . '", "' . $ideaId . '", "' . $comment . '");';
-
- // Insert new or update old description
- db_query_no_return($database, $query);
-
- // Declare query
- $query = 'SELECT comments.id, user.name
- FROM comments
- INNER JOIN user ON comments.collaborator = user.username
- WHERE comments.collaborator = "' . $collaborator . '"
- AND comments.date = "' . $date . '";';
-
- // Run query
- $recordSet = db_query_return($database, $query);
-
- // Declarations
- $returnData = Array();
-
- // Get the records
- $record = $recordSet->fetch_assoc();
-
- // Remember the records
- $returnData[] = $record["id"];
- $returnData[] = $record["name"];
- $returnData[] = $date;
-
- mysqli_free_result($recordSet);
-
- echo(json_encode($returnData));
-
- // Close the connection to the database
- db_close($database);
- }
- catch(Exception $e) {
- $errorMsg = $e->getMessage();
- print_r($errorMsg);
- }
- ?>
|