From 328f0665f3832ef180d3399d6fb6153545d6c6bd Mon Sep 17 00:00:00 2001 From: Hendrik Date: Thu, 26 Jan 2017 11:35:18 +0100 Subject: [PATCH 1/2] add basic post functionality --- website/public/API/postComment.php | 16 ++++++++++++++++ website/public/API/postPost.php | 17 +++++++++++++++++ website/queries/post.php | 2 +- website/views/post-view.php | 5 +++-- website/views/profile.php | 6 +++--- 5 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 website/public/API/postComment.php create mode 100644 website/public/API/postPost.php diff --git a/website/public/API/postComment.php b/website/public/API/postComment.php new file mode 100644 index 0000000..c5b30cc --- /dev/null +++ b/website/public/API/postComment.php @@ -0,0 +1,16 @@ +prepare(" + $stmt = $GLOBALS["db"]->prepare(" INSERT INTO `comment` ( `postID`, diff --git a/website/views/post-view.php b/website/views/post-view.php index 044c23e..0f091a6 100644 --- a/website/views/post-view.php +++ b/website/views/post-view.php @@ -21,8 +21,9 @@ echo("
-
-
+ + +
diff --git a/website/views/profile.php b/website/views/profile.php index 19b9eae..404d957 100644 --- a/website/views/profile.php +++ b/website/views/profile.php @@ -58,9 +58,9 @@ if ($_SESSION["userID"] === $userID) { ?>
-
- - + + +
From 91aca6baa740f48958435a3f12ee608cbd8d4e14 Mon Sep 17 00:00:00 2001 From: Hendrik Date: Thu, 26 Jan 2017 12:21:01 +0100 Subject: [PATCH 2/2] change comments to use ajax --- website/public/API/postComment.php | 14 ++++++++------ website/public/js/post.js | 18 ++++++++++++++++++ website/public/js/profile.js | 8 -------- website/public/profile.php | 2 +- website/views/post-view.php | 6 +++--- 5 files changed, 30 insertions(+), 18 deletions(-) create mode 100644 website/public/js/post.js diff --git a/website/public/API/postComment.php b/website/public/API/postComment.php index c5b30cc..b840e0b 100644 --- a/website/public/API/postComment.php +++ b/website/public/API/postComment.php @@ -5,12 +5,14 @@ session_start(); require("../../queries/post.php"); require("../../queries/connect.php"); require("../../queries/checkInput.php"); - if (empty($_POST['newcomment-content'])) { + echo 0; } else { - makeComment($_POST['postID'], + if(makeComment($_POST['postID'], $_SESSION['userID'], - test_input($_POST['newcomment-content'])); -} - -header("Location: ../profile.php"); \ No newline at end of file + test_input($_POST['newcomment-content']))) { + echo 1; + } else { + echo 0; + } +} \ No newline at end of file diff --git a/website/public/js/post.js b/website/public/js/post.js new file mode 100644 index 0000000..62ace68 --- /dev/null +++ b/website/public/js/post.js @@ -0,0 +1,18 @@ +function postComment() { + $.post( + "API/postComment.php", + $("#newcommentform").serialize() + ); + + $("#newcomment").val(""); + + //reload post + $.get( + "API/loadPost.php", + $("#newcommentform").serialize() + ).done(function (data) { + $('#modal-response').html(data); + }); +} + + diff --git a/website/public/js/profile.js b/website/public/js/profile.js index 2a47dce..e69de29 100644 --- a/website/public/js/profile.js +++ b/website/public/js/profile.js @@ -1,8 +0,0 @@ -function loadPost(postID) { - $.get( - "API/loadPost.php", - $(postID).serialize() - ).done(function (data) { - $('#modal-response').innerHTML= JSON.parse(data); - }); -} \ No newline at end of file diff --git a/website/public/profile.php b/website/public/profile.php index d2d3c3f..c8f27c4 100644 --- a/website/public/profile.php +++ b/website/public/profile.php @@ -3,7 +3,7 @@ - +