0

I have a form that i want to submit comments to a database containing film information. In the same div tag as the form as i have a php script that loads the comments from the database relating to the film_id people are commenting on.

The form code is this

<p>Add a Comment</p>
<form id="addCommentForm" method="post">
<div>
<input type="hidden" name="hidden" id="hidden" value="54">
<label for="name">Your Name</label>
<input type="text" name="name" id="name" />

<label for="body">Comment Body</label>
<textarea name="comment" id="comment" cols="20" rows="5"></textarea>

<input type="submit" id="comment" class="button" value="Submit" />
</div>
</form>

The hidden value contains an id number for the film the people are commenting on. I have this javascript -

<script type="text/javascript">
                                    $(".button").click(function() {

        var name = $("input#name").val();
        var comment = $("input#comment").val();
        var filmnumber = $("input#hidden").val();

        var dataString = 'name='+ name + '&comment=' + comment + '&filmnumber=' + filmnumber;

    $.ajax({
      type: "POST",
      url: "comment.php",
      data: dataString,
      success: function() {

        $('#<?php echo $row['Films_ID'] ?>').fadeOut('slow');
    document.getElementById(<?php echo $row['Films_ID'] ?>).innerHTML=xmlhttp.responseText;
    $('#<?php echo $row['Films_ID'] ?>').fadeIn('slow');
      }
     });

I want it to send the data to my php page called comment and then refresh the div (the div number is the film_id relating to the comment).

My php page that i want it to send to is this -

<?php

    $comment_name =  $_POST["name"];
    $comment_body =  $s_POST["comment"];
    $film_no =  $s_POST["filmnumber"];

    // Connects to your Database 
     mysql_connect("localhost", "****", "****") or die(mysql_error()); 
     mysql_select_db("ignitet1_CheckFilm") or die(mysql_error()); 

    $query1 = "INSERT INTO film_comments (comment_id,Films_ID,name,comment) 
    VALUES ('','$film_no', '$comment_name','$comment_body')";
    $runquery1 = mysql_query($query1)or die(mysql_error()); 

?>

Thanks for your help guys!

4

1 回答 1

0

像添加条目一样使用 AJAX,或者在添加新条目的同一调用中获取更新的列表,或者在之后进行第二次调用,并使用此结果来填充页面上的评论。

于 2012-05-02T16:18:28.517 回答