Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

developed the back end of blog system #79

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/html/about.html → client/html/about.htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ <h3><a href="#">Susan hardson</a></h3>
//establish connection to the mysql database using mysqli acess layer
$serverName = 'localhost';
$userName = 'root';
$passWord = '';
$passWord = 'Debmukh@2206';
$dbName = 'orphansupport';

$db = new mysqli($serverName, $userName, $passWord, $dbName);
Expand Down
14 changes: 13 additions & 1 deletion client/html/blog-single.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

<!DOCTYPE html>
<html lang="en">

Expand Down Expand Up @@ -498,4 +499,15 @@ <h3>Contact Us</h3>
</body>

<!-- Mirrored from html.commonsupport.xyz/2019/loveus/blog-single.html by HTTrack Website Copier/3.x [XR&CO'2014], Sun, 25 Oct 2020 16:05:09 GMT -->
</html>
</html>

var comments = "<div class='comment-box'><div class='comment'> <h4 class='name'><div class='comment-info'>" + data[i]['comment_sender_name'] +
"</h4><div class='time'>" + data[i]['date'] + "</div></div><div class='text'>" + data[i]['comment'] + " </div></div></div>"



comments = "<div class='comment-row'>"+
"<div class='comment-info'><span class='commet-row-label'>from</span> <span class='posted-by'>" + data[i]['comment_sender_name'] + " </span> <span class='commet-row-label'>at</span> <span class='posted-at'>" + data[i]['date'] + "</span></div>" +
"<div class='comment-text'>" + data[i]['comment'] + "</div>"+
"<div><a class='btn-reply' onClick='postReply(" + commentId + ")'>Reply</a></div>"+
"</div>";
669 changes: 669 additions & 0 deletions client/html/blog-single.php

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/html/blog.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
../assets/<!DOCTYPE html>
<!DOCTYPE html>
<html lang="en">

<!-- Mirrored from html.commonsupport.xyz/2019/loveus/blog.html by HTTrack Website Copier/3.x [XR&CO'2014], Sun, 25 Oct 2020 16:05:09 GMT -->
Expand Down
589 changes: 589 additions & 0 deletions client/html/blog.php

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions client/html/comment-add.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
require_once ("db.php");
$commentId = isset($_POST['comment_id']) ? $_POST['comment_id'] : "";
$comment = isset($_POST['comment']) ? $_POST['comment'] : "";
$commentSenderName = isset($_POST['name']) ? $_POST['name'] : "";
$date = date('Y-m-d H:i:s');

$sql = "INSERT INTO tbl_comment(parent_comment_id,comment,comment_sender_name, date) VALUES ('" . $commentId . "','" . $comment . "','" . $commentSenderName . "','" . $date . "')";

$result = mysqli_query($conn, $sql);

if (! $result) {
$result = mysqli_error($conn);
}
echo $result;
?>
15 changes: 15 additions & 0 deletions client/html/comment-list.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

require_once ("db.php");
$sql = "SELECT * FROM tbl_comment ORDER BY parent_comment_id asc, comment_id asc";

$result = mysqli_query($conn, $sql);
$record_set = array();
while ($row = mysqli_fetch_assoc($result)) {
array_push($record_set, $row);
}
mysqli_free_result($result);

mysqli_close($conn);
echo json_encode($record_set);
?>
4 changes: 4 additions & 0 deletions client/html/db.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php
$conn = mysqli_connect("localhost","root","","orphansupport");

?>
202 changes: 202 additions & 0 deletions client/html/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
<html>

<head>
<!-- <style>
body {
font-family: Arial;
width: 550px;
}

.comment-form-container {
background: #F0F0F0;
border: #e0dfdf 1px solid;
padding: 20px;
border-radius: 2px;
}

.input-row {
margin-bottom: 20px;
}

.input-field {
width: 100%;
border-radius: 2px;
padding: 10px;
border: #e0dfdf 1px solid;
}

.btn-submit {
padding: 10px 20px;
background: #333;
border: #1d1d1d 1px solid;
color: #f0f0f0;
font-size: 0.9em;
width: 100px;
border-radius: 2px;
cursor:pointer;
}

ul {
list-style-type: none;
}

.comment-row {
border-bottom: #e0dfdf 1px solid;
margin-bottom: 15px;
padding: 15px;
}

.outer-comment {
background: #F0F0F0;
padding: 20px;
border: #dedddd 1px solid;
}

span.commet-row-label {
font-style: italic;
}

span.posted-by {
color: #09F;
}

.comment-info {
font-size: 0.8em;
}
.comment-text {
margin: 10px 0px;
}
.btn-reply {
font-size: 0.8em;
text-decoration: underline;
color: #888787;
cursor:pointer;
}
#comment-message {
margin-left: 20px;
color: #189a18;
display: none;
}
</style> -->
<title>Comment System using PHP and Ajax</title>
<script src="jquery-3.2.1.min.js"></script>


<body>
<h1>Comment System using PHP and Ajax</h1>
<div class="comment-form-container">
<form id="frm-comment">
<div class="input-row">
<input type="hidden" name="comment_id" id="commentId"
placeholder="Name" /> <input class="input-field"
type="text" name="name" id="name" placeholder="Name" />
</div>
<div class="input-row">
<textarea class="input-field" type="text" name="comment"
id="comment" placeholder="Add a Comment"> </textarea>
</div>
<div>
<input type="button" class="btn-submit" id="submitButton"
value="Publish" onclick = "postReply(0)"><div id="comment-message">Comments Added Successfully!</div>
</div>

</form>
</div>
<div id="output"></div>
<script>
function postReply(commentId) {
$('#commentId').val(commentId);
$("#name").focus();
}

$("#submitButton").click(function () {
$("#comment-message").css('display', 'none');
var str = $("#frm-comment").serialize();

$.ajax({
url: "comment-add.php",
data: str,
type: 'post',
success: function (response)
{
var result = eval('(' + response + ')');
if (response)
{
$("#comment-message").css('display', 'inline-block');
$("#name").val("");
$("#comment").val("");
$("#commentId").val("");
listComment();
} else
{
alert("Failed to add comments !");
return false;
}
}
});
});

$(document).ready(function () {
listComment();
});

function listComment() {
$.post("comment-list.php",
function (data) {
var data = JSON.parse(data);

var comments = "";
var replies = "";
var item = "";
var parent = -1;
var results = new Array();

var list = $("<ul class='outer-comment'>");
var item = $("<li>").html(comments);

for (var i = 0; (i < data.length); i++)
{
var commentId = data[i]['comment_id'];
parent = data[i]['parent_comment_id'];

if (parent == "0")
{
comments = "<div class='comment-row'>"+
"<div class='comment-info'><span class='commet-row-label'>from</span> <span class='posted-by'>" + data[i]['comment_sender_name'] + " </span> <span class='commet-row-label'>at</span> <span class='posted-at'>" + data[i]['date'] + "</span></div>" +
"<div class='comment-text'>" + data[i]['comment'] + "</div>"+
"<div><a class='btn-reply' onClick='postReply(" + commentId + ")'>Reply</a></div>"+
"</div>";

var item = $("<li>").html(comments);
list.append(item);
var reply_list = $('<ul>');
item.append(reply_list);
listReplies(commentId, data, reply_list);
}
}
$("#output").html(list);
});
}

function listReplies(commentId, data, list) {
for (var i = 0; (i < data.length); i++)
{
if (commentId == data[i].parent_comment_id)
{
var comments = "<div class='comment-row'>"+
" <div class='comment-info'><span class='commet-row-label'>from</span> <span class='posted-by'>" + data[i]['comment_sender_name'] + " </span> <span class='commet-row-label'>at</span> <span class='posted-at'>" + data[i]['date'] + "</span></div>" +
"<div class='comment-text'>" + data[i]['comment'] + "</div>"+
"<div><a class='btn-reply' onClick='postReply(" + data[i]['comment_id'] + ")'>Reply</a></div>"+
"</div>";
var item = $("<li>").html(comments);
var reply_list = $('<ul>');
list.append(item);
item.append(reply_list);
listReplies(data[i].comment_id, data, reply_list);
}
}
}
</script>
</body>

</html>
4 changes: 4 additions & 0 deletions client/html/jquery-3.2.1.min.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions client/html/login.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@


<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
Expand Down
Loading