Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. <script>
  2. <div class="col-md-6">
  3. <h3>Add a comment</h3>
  4.  
  5. <form action="" class="form-inline" id="comment_form" method="POST">
  6.  
  7. <div class="form-group">
  8. <textarea name="commentaire" id="commentaire" cols="60" rows="10"
  9. class="form-control"></textarea>
  10. </div>
  11. <div class="form-group">
  12. <input type="submit" class="btn btn-primary" value="ENVOYER"
  13. id="submit" name="submit">
  14. </div>
  15. </form>
  16. <span id="comment_message"></span>
  17. </div>
  18. $(document).ready(function(){
  19. $('#comment_form').on('submit', function(event){
  20. event.preventDefault();
  21. var form_data = $(this).serialize();
  22. var id = <?php echo $id; ?>;
  23. $.ajax({
  24. url:"add_comment.php",
  25. method:"POST",
  26. data:{form_data,id},
  27. dataType:"JSON",
  28. success:function(data)
  29. {
  30. if(data.error != '')
  31. {
  32. $('#comment_form')[0].reset();
  33. $('#comment_message').html(data.error);
  34. load_comment();
  35. }
  36. }
  37. })
  38. });
  39. </script> ```
  40.  
  41. <?php
  42. require_once("../Ressources/Config.php");
  43.  
  44.  
  45.  
  46. $error = '';
  47. $comment_content = '';
  48. $id_user=$_SESSION['id_user'];
  49. $id_produit=$_GET['id'];
  50.  
  51. if(empty($_POST["commentaire"]))
  52. {
  53. $error .= '<p class="text-danger">Comment is required</p>';}
  54. else
  55. {
  56. $comment_content = $_POST["commentaire"];
  57. }
  58.  
  59. if($error == '')
  60. {
  61. $query =query(" INSERT INTO commentaires (id_produit, id_user, com,
  62. date_a)
  63. VALUES ($id_produit, $id_user, $comment_content, curdate()) ");
  64. confirm($query);
  65.  
  66.  
  67. $data = array(
  68. 'error' => $error
  69. );
  70.  
  71. echo json_encode($data);
  72.  
  73. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement