0
<?php 
if(isset($_POST['add_comment'])){

$agent_id = mysql_real_escape_string(htmlentities($_POST['agent_id']));
$comment_id = mysql_real_escape_string(htmlentities($_POST['bookId']));
$comment = mysql_real_escape_string(htmlentities($_POST["business_comment"]));

// insert comment/reply
$sql_upd_feedback = "UPDATE b_feedback SET feedback_comment='$comment' WHERE feedback_id='$comment_id'";
$query_upd_feedback = mysql_query($sql_upd_feedback) or die(mysql_error());

if($query_upd_feedback){
    header("Location: feedback.php?aid=" . $agent_id);
}
else {
    header("Location: feedback.php?aid=" . $agent_id);
}
}
else {
header("Location: logout.php");
}
?>

<script>
    $(document).on("click", ".open-AddBookDialog", function (e) {

    e.preventDefault();

    var _self = $(this);

    var myBookId = _self.data('id');
    $("#bookId").val(myBookId);

    $(_self.attr('href')).modal('show');
    });
</script>


<!-- form in modal -->
    <div class="modal fade" id="addBookDialog">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-body">
                    <div class="row">
                        <div class="col-sm-12">
                            <form role="form" action="add_feedback_comment_script.php" method="post">
                            <div class="form-group">
                                <label>Comment</label>
                                <textarea name="business_comment" class="form-control" rows="2"></textarea>
                            </div>
                            <input type="text" name="bookId" id="bookId" hidden/>
                            <input type="text" name="agent_id" value="<?php echo $agent_id; ?>" hidden/>
                            <div class="checkbox m-t-lg">
                                <button type="submit" name="add_comment" class="btn btn-sm btn-success pull-right text-uc m-t-n-xs"><strong>Comment</strong></button>
                            </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
    </div>
        <!-- /.modal-dialog -->

Hello... I want to pick the values from the modal especially the bookId value and use it in my php code. The value in the modal is set with the javascript code but Im having troubling retrieving it from the external php file. Please anyone help???

Aine Evans
  • 106
  • 8
  • 1
    If you can, you should [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) [statements](http://php.net/manual/en/pdo.prepared-statements.php) instead, and consider using PDO, [it's really not hard](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Jul 20 '15 at 13:05

1 Answers1

2

A few strange things in your code:

Use mysqli_* instead of mysql_*

What is the point of this if statement?

if($query_upd_feedback){
    header("Location: feedback.php?aid=" . $agent_id);
}
else {
    header("Location: feedback.php?aid=" . $agent_id);
}

What is this?

 <input type="text" name="bookId" id="bookId" hidden/>

Did you maybe mean:

 <input type="hidden" name="bookId" id="bookId"/>

Also here:

<input type="text" name="agent_id" value="<?php echo $agent_id; ?>" hidden/>

You probably mean:

<input type="hidden" name="agent_id" value="<?php echo $agent_id; ?>">

And what does rows="2" mean in your textarea?

And to debug, simply first inspect the posting:

if(isset($_POST['add_comment'])){
  echo "<pre>";  
  print_r($_POST);
  echo "</pre>";
  exit;
  .... rest....

DOes that produce your expected values for all elements in your form?

Erwin Moller
  • 2,375
  • 14
  • 22
  • Did you debug? DId you echo $sql_upd_feedback? WHat is the returnvalue of the mysql_query($sql_upd_feedback)?? You have to try to debug such thing yourself, since nobody over here has a crystal ball. ;-) Give some more information. Also: Did you inspect the errorlog? EDIT: I hear it works now, but I have no idea why. ;-) I hope you do. – Erwin Moller Jul 20 '15 at 13:34