Live PHP Comment System using Ajax Jquery

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello friends in this video tutorial we are going to learn PHP ajax-based comment system in this system user can comment and another user can reply on that comment in this system user can reply n level comment in short it will make conversation with contents owner and reader of that content by comment system content so may get feedback from reader of their content and user can send suggestion to content owner and another user also adds some more idea and sent to content owner in this system user can post comment without refresh of web page because we have use Ajax for send and receive data from MySQL table by using PHP script here we will make nested comment system by using PHP with Ajax that means user can reply on parent comment and then after on sub comment also user can reply this way we will make nested live commenting system by using PHP script with Ajax query and MySQL database you now let's start discuss this topic this is our testing database and in this we have one comment table with five table column like commented parent commented comment comment send a name and date here commented his primary key of this table when use a post fresh comment then in parent commented table column we will store 0 value but when other user apply on particular comment then in parent comment SID we will store it of comment on which he has reply so this is simple database structure for comment and reply on that comment and comment data we will store in this table this is index page and on this page we have already include JavaScript's library in bootstrap library link we will use feature of both library on this page after this on this page first we have make comment form for post comment so we have write form attribute method is equal to post and it is equal to comment form under this form for define one input type is equal to text with attribute name is equal to comment name and it is equal to comment name under this text box user can type his name below this we have defined text area tag with attribute name is equal to comment content and it is equal to comment content under this tag we can type comment content lastly under this form we have define input type is equal to submit with attribute name is equal to submit it is equal to submit and value is equal to submit by click on this button we can send comment data to server below this button we have defined with attribute it is equal to comment message under this tag we will display error or success message here we have defined one more division tag with attribute it is equal to display comment under this tag we will display submitted comment on webpage using Ajax now we have moved to write query code and under this first we want to submit comment data so we have write dollar with for mid comment form with our method with submit event so when form submitted this code will execute under this first we have right events dot preventdefault method this method will stop submitting form data to server after this we have defined form data variable is equal to dollar this with serialized method this method will convert form data to URL encoded string now we have start write ajax request so under this first we have write URL option set to @ comments dot PHP page here we have send request to this page in second option we have right method and under this we can define which method we should use for sent data to server so here we have used post method for send data to server in third option we have right data under this option we can define which data we want send to server so here we have write form data in which we have store comment form data in fourth option we have right data type in this option we can define in which data type we want to received data so here we have defined lastly we have write success callback function this function has been called if request completed successfully and it will receive data from server under this function we have right if statement and under condition we have right data dot error value is not equal to blank if this condition true then it will execute if block of code under this block we have right dollar with for mid comment form with zero index with reset method this code will reset form field after this we want to display message under division tag with it comment message so we have write dollar with it comment message with HTML method with data dot error it will display error or success message on webpage now we have moved to write PHP code for add comment so we have go to add comment PHP page and on this page first we have make database connection after making database connection we have defined three variable like dollar error comment name and comment content with blank value below this we have right if statement and under condition we have right empty function with dollar post comment name variable this condition will check if this variable has no value then it will execute if block otherwise it will execute else block suppose above condition true then it will execute if block and under this block we have right dollar error variable and under this variable we have a pend message like name is required but suppose above condition false then it will execute else block of code and under this block we have write dollar comment name variable is equal to dollar post comment name variable same way we have again right if statement and under condition we have right empty function with dollar post comment content variable this condition will check if this variable has no value then it will execute if block otherwise it will execute else block of code suppose above condition true then it will execute if block and under this block we have write dollar err variable and under this variable we have a pend message like comment is required but suppose above condition false then it will execute else block of code and under this block we have write dollar comment content variable is equal to dollar post comment content variable now we have right if statement and under condition we have right dollar error variable is equal to blank value if this condition true that means there is no validation error and it will execute if block of code under this block we have right dollar query variable is equal to insert into comment table with table column like parent commented comment and comment send a name with values like double colon parent commented comment and comment send a name below this we have right dollar statement variable is equal to dollar Connect variable with preparer method with dollar query variable it will make query for execution now we want to execute this query so we have right dollar statement variable with execute method with value pass in array format this method will execute insert query after this we have a right dollar err variable is equal to message like comment added now here we have right dollar data variable is equal to array with key error with dollar error variable so here we have store output in array lastly we want to send this data to Ajax script so we have right echo statement which an encode method with dollar date variable this method will convert array at some string and sent to Ajax now we have check output in browser friends we can see when page has been loaded into browser then we can see simple comment form when we have directly click on submit button then we have received message like name and comment is required so in name we have write John Smith and in comment we have write nice post and click on submit button after clicking on submit button we have received comment added message on web page now we want to load comment on web page so we have go to index page and here we have creates load comment function this function will load comment on web page under this function we have right dollar ajax.request and under this first we have right URL option set to fetch comment dot PHP page here we have send request to this page in second option we have right method and under this we have right post method for send data to server lastly we have write success callback function this function has been called if request completed successfully and it will receive data from server under this function we have write dollar with division tag it display comments with HTML method with data this code will display comment on webpage you now we have goal to fetch comment dot PHP page and on this page first we have make database connection after this we have right dollar query variable is equal to select staff from comment table where parent commented is equal to zero order by commented in descending order this query only select parent comment whose parent commented is zero below this we have right dollar statement variable is equal to dollar Connect variable with preparer method with dollar query variable this code will make query for execution now we want to execute query so we have right dollar statement variable with execute method this method will execute query after this we have right dollar result variable is equal to dollar statement variable with fetch all method this method will fetch query execution day to and store into this dollar result variable now we have right for a rich loop with dollar result variable with dollar a variable by using this loop we can fetch data from dollar result variable under this loop we have a right dollar output variable and under this variable we have a pen date tml code like division tag with class is equal to panel panel default this is bootstrap panel class under this tag we have right division tag with attribute class is equal to panel heading and under this we have right dollar a comment send a name and dollar rotate variable below this we have right division tag with attribute class is equal to panel body and done to this tag we have right dollar a comment variable it will print comment data on under this tag lastly we want to define reply button so we have write division tag with attribute class is equal to panel footer and under this tag we have right button tag with type is equal to button class is equal to reply and it is equal to dollar bro commented variable this way we have make reply button in which we have defined reply class which we will use Dinge query code and in it attribute we have store commented by click on this button user can reply on particular comments now we have right echo statement with dollar output variable this will display comment data on webpage now we have go to Exce page and here we have called load comment function so when page been low then this function will call and it will display comment a2 on webpage now we have saved this code in check output in browser here we can see no comment on webpage so we have a fresh web page and after refresh of page comment data has been seen on web page now we have moved to write reply comment code [Music] so we have go-to index page and here in forum we have defined one hidden tag with attribute name is equal to commented and it is equal to commented and value is equal to zero under this tag we will store it of particular comment now we have goated Squier and here we have right dollar with document selector with on methods and under this method we have right click event with button class replay so when we have click on reply button this code will execute under this first we have defined commented variable is equal to dollar this with attribute method with it this code will fetch it value from reply button and store into this commented variable after this we have right dollar with hidden Tagget commented with value methods and under this we have right commented variable lastly we have right dollar with text box it'd comment name with focus method this code will focus cursor on this comment name text box now we have seen output in browser friends here when we can see comment with reply button when we have click on this button cursor has been focus on comment name textbox so here we have right Peter Parker and in comment content we have right thanks and click on submit button after click on submit button comment has been submitted and and here we cannot see submitted reply comment on webpage for display reply comment on webpage below parent comments so for this we have go to fetch comment dot PHP page and on this page we have create get reply comment recursive function with three argument like dollar connect variable dollar parented is equal to zero and dollar margin left is equal to zero this function will fetch n level reply comment of particular parent comment under this function we have write dollar query variable is equal to select star from comment table where parent commented is equal to dollar parented variable this query will fetch comment data of particular parent comment below this we have a right dollar statement variable is equal to dollar Connect variable with preparer statement with dollar query variable this code make query for execution now we want to execute query so we have right dollar statement variable with execute method this will execute query after this we have right dollar result variable is equal to dollar statement variable with fetch all method this method will fetch query execution day to and store into dollar result variable now we have right dollar count variable is equal to dollar statement variable with row count method this method will return number of rows in query execution below this we have write if statement and under condition we have write dollar parented variable value is equal to zero if this condition true then it will execute if block otherwise it will execute else block of code suppose this condition true then it will execute if block and under this block we have write dollar margin left variable is equal to zero but suppose above condition false then it will execute else block of code and under this block we have write dollar margin left variable is equal to dollar margin left variable plus 48 now we have write if statement and under condition we have write dollar count variable value is greater than 0 if this condition true then it will execute if block of code under this block we have right for each loop and under condition we have right dollar result variable as dollar a variable by using for each loop we can fetch data from dollar result variable under this loop we have write dollar output variable and under this variable we have a pen day CH tml code like division tag with class is equal to panel panel default with style attribute margin left set to dollar margin left variable under this tag we have right division tag with attribute class is equal to panel heading and under this we have right dollar a comment send a name and dollar rotate variable below this we have right division tag with attribute class is equal to panel body and done to this tag we have right dollar a comment variable it will print comment data on under this tag lastly we want to define reply button so we have write division tag with attributes class is equal to panel footer and under this tag we have right button tag with type is equal to button class is equal to reply and it is equal to dollar row commented variable now we have again right dollar output variable and under this variable we have a pen code like this reply comment function with three argument like dollar Connect variable dollar Oh commented variable and dollar margin left variable here we have called this function because we want to fetch n level reply comment of particular parent comment and this type of function we have called recursive function lastly we have write returns statement with dollar output variable this is the output of this function now here we have again right dollar output variable and here we have called this get reply comment function with two arguments like dollar connects variable and dollar bro commented variable it will fetch reply comment day two and appended into this dollar output variable now we have saved this code in check output in browser here we can see only parent comments but we cannot see reply comment so we have a fresh page and now we can see parent and reply comment has been display in different style now we have again reply on reply comment and here we have click on this reply comments reply button and here in name we have write John Smith and in comment content we have write you welcome and click on submit button - clicking on submit button we can see parent comment and below it we can see to reply comment now we have again go to name textbox and here we have write dona huber and comment content we have write we are waiting for more post and click on submit button after clicking on submit button we can see parent comment without refresh of webpage now we want to reply on this comment so we have click on reply button and cursor go to name textbox and here we have write Peter Parker and in comment content we have write thanks and click on submit button - clicking on submit button we can see reply comment below dona who the parent comment so this way we can make common system by using PHP scripts with Ajax if you have any query regarding this video tutorial part please comment your query in comment box and if you liked this video tutorial please share with your friends or even you can also share on social media also if you want to get more update regarding our video tutorial please subscribe our YouTube channel forget more update regarding release of future video lastly keep watching our YouTube channel thanks for watching this video tutorial
Info
Channel: Webslesson
Views: 76,665
Rating: undefined out of 5
Keywords: comment system in php, php comment system, comment system in php mysql, php comment system with reply, comment system, php comment box tutorial, comment system in php ajax, php comment system tutorial, comment system with php and jquery, comment system for website, comment system using php and mysql, comment system using ajax jquery and php, comment system using php, php nested comment system
Id: 7Gj_zWCHTIk
Channel Id: undefined
Length: 24min 27sec (1467 seconds)
Published: Fri Dec 29 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.