Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- <div class="col-md-6">
- <h3>Add a comment</h3>
- <form action="" class="form-inline" id="comment_form" method="POST">
- <div class="form-group">
- <textarea name="commentaire" id="commentaire" cols="60" rows="10"
- class="form-control"></textarea>
- </div>
- <div class="form-group">
- <input type="submit" class="btn btn-primary" value="ENVOYER"
- id="submit" name="submit">
- </div>
- </form>
- <span id="comment_message"></span>
- </div>
- $(document).ready(function(){
- $('#comment_form').on('submit', function(event){
- event.preventDefault();
- var form_data = $(this).serialize();
- var id = <?php echo $id; ?>;
- $.ajax({
- url:"add_comment.php",
- method:"POST",
- data:{form_data,id},
- dataType:"JSON",
- success:function(data)
- {
- if(data.error != '')
- {
- $('#comment_form')[0].reset();
- $('#comment_message').html(data.error);
- load_comment();
- }
- }
- })
- });
- </script> ```
- <?php
- require_once("../Ressources/Config.php");
- $error = '';
- $comment_content = '';
- $id_user=$_SESSION['id_user'];
- $id_produit=$_GET['id'];
- if(empty($_POST["commentaire"]))
- {
- $error .= '<p class="text-danger">Comment is required</p>';}
- else
- {
- $comment_content = $_POST["commentaire"];
- }
- if($error == '')
- {
- $query =query(" INSERT INTO commentaires (id_produit, id_user, com,
- date_a)
- VALUES ($id_produit, $id_user, $comment_content, curdate()) ");
- confirm($query);
- $data = array(
- 'error' => $error
- );
- echo json_encode($data);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement