php code for comment system

Solutions on MaxInterview for php code for comment system by the best coders in the world

showing results for - "php code for comment system"
Liah
23 Nov 2020
1// This is a single-line comment
2
3# This is also a single-line comment
4
5/*
6This is a multiple-lines comment block
7that spans over multiple
8lines
9*/
Alexander
21 Apr 2017
1<?php
2// This is a single-line comment
3
4# This is also a single-line comment
5  
6/*
7This is a multiple-lines comment block
8that spans over multiple
9lines
10*/
11  
12// You can also use comments to leave out parts of a code line
13$x = 5 /* + 15 */ + 5;
14echo $x;
15?>
Silvia
17 Oct 2018
1//...
2// If the user clicked submit on comment form...
3if (isset($_POST['comment_posted'])) {
4	global $db;
5	// grab the comment that was submitted through Ajax call
6	$comment_text = $_POST['comment_text'];
7	// insert comment into database
8	$sql = "INSERT INTO comments (post_id, user_id, body, created_at, updated_at) VALUES (1, " . $user_id . ", '$comment_text', now(), null)";
9	$result = mysqli_query($db, $sql);
10	// Query same comment from database to send back to be displayed
11	$inserted_id = $db->insert_id;
12	$res = mysqli_query($db, "SELECT * FROM comments WHERE id=$inserted_id");
13	$inserted_comment = mysqli_fetch_assoc($res);
14	// if insert was successful, get that same comment from the database and return it
15	if ($result) {
16		$comment = "<div class='comment clearfix'>
17					<img src='profile.png' alt='' class='profile_pic'>
18					<div class='comment-details'>
19						<span class='comment-name'>" . getUsernameById($inserted_comment['user_id']) . "</span>
20						<span class='comment-date'>" . date('F j, Y ', strtotime($inserted_comment['created_at'])) . "</span>
21						<p>" . $inserted_comment['body'] . "</p>
22						<a class='reply-btn' href='#' data-id='" . $inserted_comment['id'] . "'>reply</a>
23					</div>
24					<!-- reply form -->
25					<form action='post_details.php' class='reply_form clearfix' id='comment_reply_form_" . $inserted_comment['id'] . "' data-id='" . $inserted_comment['id'] . "'>
26						<textarea class='form-control' name='reply_text' id='reply_text' cols='30' rows='2'></textarea>
27						<button class='btn btn-primary btn-xs pull-right submit-reply'>Submit reply</button>
28					</form>
29				</div>";
30		$comment_info = array(
31			'comment' => $comment,
32			'comments_count' => getCommentsCountByPostId(1)
33		);
34		echo json_encode($comment_info);
35		exit();
36	} else {
37		echo "error";
38		exit();
39	}
40}
41// If the user clicked submit on reply form...
42if (isset($_POST['reply_posted'])) {
43	global $db;
44	// grab the reply that was submitted through Ajax call
45	$reply_text = $_POST['reply_text']; 
46	$comment_id = $_POST['comment_id']; 
47	// insert reply into database
48	$sql = "INSERT INTO replies (user_id, comment_id, body, created_at, updated_at) VALUES (" . $user_id . ", $comment_id, '$reply_text', now(), null)";
49	$result = mysqli_query($db, $sql);
50	$inserted_id = $db->insert_id;
51	$res = mysqli_query($db, "SELECT * FROM replies WHERE id=$inserted_id");
52	$inserted_reply = mysqli_fetch_assoc($res);
53	// if insert was successful, get that same reply from the database and return it
54	if ($result) {
55		$reply = "<div class='comment reply clearfix'>
56					<img src='profile.png' alt='' class='profile_pic'>
57					<div class='comment-details'>
58						<span class='comment-name'>" . getUsernameById($inserted_reply['user_id']) . "</span>
59						<span class='comment-date'>" . date('F j, Y ', strtotime($inserted_reply['created_at'])) . "</span>
60						<p>" . $inserted_reply['body'] . "</p>
61						<a class='reply-btn' href='#'>reply</a>
62					</div>
63				</div>";
64		echo $reply;
65		exit();
66	} else {
67		echo "error";
68		exit();
69	}
70}
Kayna
20 Sep 2018
1$(document).ready(function(){
2	// When user clicks on submit comment to add comment under post
3	$(document).on('click', '#submit_comment', function(e) {
4		e.preventDefault();
5		var comment_text = $('#comment_text').val();
6		var url = $('#comment_form').attr('action');
7		// Stop executing if not value is entered
8		if (comment_text === "" ) return;
9		$.ajax({
10			url: url,
11			type: "POST",
12			data: {
13				comment_text: comment_text,
14				comment_posted: 1
15			},
16			success: function(data){
17				var response = JSON.parse(data);
18				if (data === "error") {
19					alert('There was an error adding comment. Please try again');
20				} else {
21					$('#comments-wrapper').prepend(response.comment)
22					$('#comments_count').text(response.comments_count); 
23					$('#comment_text').val('');
24				}
25			}
26		});
27	});
28	// When user clicks on submit reply to add reply under comment
29	$(document).on('click', '.reply-btn', function(e){
30		e.preventDefault();
31		// Get the comment id from the reply button's data-id attribute
32		var comment_id = $(this).data('id');
33		// show/hide the appropriate reply form (from the reply-btn (this), go to the parent element (comment-details)
34		// and then its siblings which is a form element with id comment_reply_form_ + comment_id)
35		$(this).parent().siblings('form#comment_reply_form_' + comment_id).toggle(500);
36		$(document).on('click', '.submit-reply', function(e){
37			e.preventDefault();
38			// elements
39			var reply_textarea = $(this).siblings('textarea'); // reply textarea element
40			var reply_text = $(this).siblings('textarea').val();
41			var url = $(this).parent().attr('action');
42			$.ajax({
43				url: url,
44				type: "POST",
45				data: {
46					comment_id: comment_id,
47					reply_text: reply_text,
48					reply_posted: 1
49				},
50				success: function(data){
51					if (data === "error") {
52						alert('There was an error adding reply. Please try again');
53					} else {
54						$('.replies_wrapper_' + comment_id).append(data);
55						reply_textarea.val('');
56					}
57				}
58			});
59		});
60	});
61});
queries leading to this page
comments script in phphow should we add a single line comment in our php code 3fcomment in php if statement psrhow to comments in phphow to add comment to your functions phpphp comments syntax parameterscode comments out phpcreating a comment and reply system php and mysqlphp code for commenttype of comments in phplike and reply comment sql in php exapleone line comment in phphow to do comments in phphow to create a multi line comment in phphpow tpo comment in phpphp see commenthow to add comments in phpcomment php codephp comment out codephp create commentcomments system phphow to make comment phplike and reply comment sql in phphow to put comment in phpadding comments phpcomment line out in phpphp long commentshtml and php code for comment and replyphp function commentsphp method commentshow to comment in php inihow comment php codehow to block a section og php codedisplay on comment the value in phphow to comment line in phphow to comment in php filecomment html in phpscript jscomment code in phpcomment system phphow to select all code and comment in phpfull comment phpcomments php htmlwhat is the correct way to add a comment in php 3fa simple commant page in phpcomments in php websitejs 2fscript jshow to comment phpcomment out using phpcoment in php 3c 21 comment in phpscripting in jsphp comment 40return or commenting out phpphp comments 40html comment system phpcomment on php pagecomment in php codephp commentdoccomments section phpphp comment code serverphp comment blockhow to add a comment in phpcommentaar phpphp 40return commentcreate a php code to comment postingcommentaar in phpphp comment 2f 2f 23 comment phpphp single line commentphp code for comment systemphp set method with commentphp large comment blockwhat is the correct way to add comment in phpscripts jscomment section phpsingle line comments in php can be written using two different prefixes 2c write the one that cannot be used in javascript php comment typesphp var commentsphp how comment blockphp comment multiple linesadding a comment in phpphp in comment 23 php commentphp cpmmentfile comment php documentrorhow to comment in phpcommend in phpmulti lines comment for php codeshow to comment your methods in phpmethod commenting phpphp comment function parametersphp how to make comments go to another pageadd comments phpline comment in phpline comments and block comment in phphow to comment a code in phpsingle line comment in phpcomments phphow do you create a comment on php scripthow to comment a lot of php codeput comments in php codecommenting oout phpmake comments php sormmulti line comment in phpcommentare phpcomment everythig phpcommentar php systemphp user comment systemhow do you write comments in php 3fcommenting in phpphp comment markshow to comment code in phpemment on php file comment php comment in php timeradd comment to echo phpphp function commentthis scriptways of commenting in phpmulti line comment phpscript javascriptphp ini comment meansphp doc commentphp comentedcoments in phphow to write comment in php ini filecomment management system in phpcomment tag in phphow to add note in php codecommenti in phpscripts jshow to make php commentshow to comment php in commentphp comment in 27 27 40 with comments in phpwhich of the following is correct to add a comment in php 3fphp comment sectionphp html commentscript javascripthow to comment out php ini linesdisplay data in php on the commentsputting a comment in phpcomment in php mysqlcomment syntax phphow to use comment in phpsingle line comments in php arephp line comment block commentphp comments systmemultiple line comment in phpcomment documentation phpusing 23 comments in phphow to add comment in php codecomment php in htm 3bphp commenting guidehow to comment php linecomment in php vodephp commentingphp commenting outcomments in phpphp code commentscomment php sectionphp add code commentsphp 3c 3f 3d 3f 3e commentcommenting in html ph 5bcomment section php mysqlscript in javascriptphp blog comment systemphp in the comment 40capture line comment phpcomment out code phpphp commenting systemhow to make comment in phprun the php code on comment linehow do you make comments statements in php 3f 2aphp function definition commentcomments in php codehow to make a comment in phpcomment html with phpphp comment 5ccommment phpcomment in php inihow to make comments in php filephp 2a 2a commentphp how to commenthow to comment a php codescript js php file how to comment correctlyhow to build a custom comment and reply systemhow do you comment in phpcommenting function in phpphp comments paracant comment in phpphp commentairecomment php code in php fileshow to write comments in php programmingphp comments syntaxcomment a line in phpadd a comment on phpcomment function php comment uot phpregistered user comments in posting system phpwhich of the following is the way to create comments in php 3fcomments for phpphp commentsput my information in comments in phpcomment block phpcomment php in phpcomments on function phphw to comment a block of code phpphp comments with 23php jquery comments and replyphp add comments to web pagefunction commenting in phpcomment php code in php filephpcs commenthow to comment on phpphp comment markhowto comment out phpphp comments exampleinurl 3acomment phpcommenting out in phpphp multi line commentget comments phpphp comment docnote in phpcomment line in phpsingle line comment in php 3fcomments phphow to comment php filehow to comment out php linehow to write comments in phpphp block commentphp comment symbolhow to comment out phpcomment and review phpcomment out php tagshow do we comment something out in phpcoments on phpphp comment systemhow to put a comment in phpphp comment functionhow to make a page in php where user can post commentphp multiline commentphp documentation commentphp commetscomment multiple lines in phpphp comment 40createcomment in a php filephp how to comment out a sectioncomment for function in phpphp comment out whole codephp how to add commentshow to comment a line in phphow to comment in return phphow to add comment in php programadd comment to parameter phpphp block comment examplephp big comment linescript in js 24 used for comment in phpplace in comment php comment php htmldo php interprete the commentscomment out in phpcomment in phppphp code commenterhow to write a comment in phpphp comment line 40methid inside commint phpphp 40 commentscomment out code in ph 5bcomment code in php 3c php code commentcomment in phpphp comments inside codesphp green comment multiple linescomment php tagswhat is al ine of code known as in phpphp comment w3schoolscommenting phphow to comment out in phphow to add comments in a php codephp script how to comment out one linemake comments in phpcomment v phpphp comment out optionsphp comment guidelineshow to script in javascriptphp comment codephp block commentsghowt o write 40param fot post in php commentcreating a comment and reply system php and mysql tutorialhow to add a comment on my method in phpcode to create a comment section in phphow to comment multiple lines in phphow to comment php tagsphp comments on methodslong comment phpcomments on post in phpscripts javascriptwhy does my php line of code considered a commenthow to comment out a php tagout comment code phpphp multiline commentsphp file commentwhen php come inphp commentarehow to create comments in phpcommenting php scripthow to document php code from commentscomment on phpphp 8 commenthow to comment function phpwhat is a correct way to add a comment in php 3fphp coimmenthow to add comments in php fileseasy way comment phpphp comment marks sectiondoc comment phpadd as comment phphow to comment out php codephp comment 3c 3fphp how to add comments n your webcomment code phpphp comment text boxphp large comment block with comments insidetypes of comments in phpcommenting php codecomment commenter en phpfacebook comment reply system javascript mysqlcomment and reply system in phpwhere comments are stored in a file phpcommenti phpcommet phphow to comment php codehow to make reply comments phpphp proper function commentshow to coment on phpsingle line comments in php can be written using two different prefixesadd php to html commented outphp comment linesscript comments phpcomment php with htmlcomment php filecomment out phpphp comentsproperly comment out php in htmlphp page commentphp comment out linephp comment out block of codeblock comment phphow to comment a large paragraph in phpcomment phphow to mail comments in html using phpphp section commentphp comment outhow to comment out php in html 40file php commentphp html comment systemcomments in php fileadd comment with phpcommment in phpcomment system in phpcomment line phpcomment inside phphow to add function comment in phpcomment fonction 3c 3d 3e phpbest way to make comments with phpcomment a paragraph phpcomments system php 2020how to comment out code phpputting php in commentscomment php in html pagephp print commentphp is it possible to write inside a commentphp inline commentsphp comentjs scriptsingle line comments in php can be written using two different prefixes 2chow to multi line comment in phpcreating comment in phpphp declare methods with commenttype comment phptips php commentsdoc comment in phpadding comment in phpadd comment on phphow to add comments to php filehow to write comment in php functionuse comment in phpphp inline commentphp large commentinline comments in php meansphp multline commentphp comment out multiple lineswriting comment in phpphp mlti comment system in phpcomment section is phpphp 23 commentcomment blocks phphow to do comment in phpcomment on php stoercomment list next previus php demoadd comments in phpsingle line comment phpfunctions comments phpdocumentation comment in phpcomment out php codehow to comment something in phpphp version doc commentsphp request commentshow to fetch comments and replies from database in php using jqueryphp comment 2a 2fphp comments systemphp get commenthow to make a code comment pjpput comment in phpcorrect way to add a comment in phpblock php commenthow to wriet comments in phpphp commenthow to make a comment and it will show in a page phpcomment out paragraph phphow to comment out php code in wordpresshow to set multiple line comments in phpmmaing comment sin phpcomment in php block codecomments in the php filephp html comment out phpcommenting symbol for phpphp comment system in phpphp comment in htmlhow comment is given in phpphp comments 23comment php inside htmlphp comment syntaxdoes php accept html style commentsphp comment boxphp commentaarphp functions commentsphp comments syntaxtmake a comment in phpcomentar php line comment in our php codephp use for long commentshow to comment php sectionphp comment 40commenter phpcomments in php 3fhow to make comments in phpadd comment in phpcomment oout phphow to coment in phpcomment in php filewhat are type of commenting lines in phpcomment blocks of code in phpphp comment liphp commetphp encode commentsphp comment descriptionscripting in javascriptphp line commentphp comment taghow do you comment out a line in php 3fcomment lines in phpphp special commentscomment system for website phphow ot give comments in phphow to write comment in phpthe difference between html comments and css comments and php commentscomment of comment phphow to commend in phpcomment php tagphp code for comment system