Click here to Skip to main content
15,896,269 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Below is a php code for inserting comment to a post, It works fine now I want to add ajax code to add comments live (without page being refreshed). I prefer ajax code and php code on same page because code will be carrying id's of users so don't want to send such data to another page through ajax/js. I am not good at programming tried few ajax codes but failed so if anyone can help me with ajax code will be thankful.

PHP
<?php
   if(isset($_POST['submit'])) {
     $comment=strip_tags($_POST['content']);
     $com = $db->prepare("INSERT INTO comments (comment,userto, userfrom, blog) VALUES (:comment, :userto, :userfrom, :blog)");
     $com->execute(array(':comment'=>$comment,':userto'=>$userid,':userfrom'=>$uid,':blog'=>$blogId));

   }
?>

HTML
<form method='post' name='form' action='' class='commentbox2'>
<textarea  name='content' id='content'></textarea><br />
<input type='submit' value='Comment' name='submit' class='comment_button'/>
</form>
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900