Fill in Modal with Bank data

0

I have a Grid where I click the edit button and it should bring DB data into a Modal but it is not working.

Follow the code.

Button

Obs. (The Button is bringing the id)

<a href="#my_modal" data-toggle="modal" data-fornecedor-id="<?php echo $rowPedido->id; ?>" >

Div for Data Return

<div class="fetched-data"></div>

Jquery

      $(document).ready(function(){
    $('#myModal').on('show.bs.modal', function (e) {
        var rowid = $(e.relatedTarget).data('fornecedor-id');
        $.ajax({
            type : 'post',
            url : 'readDetails.php', //Here you will fetch records 
            data :  'rowid='+ rowid, //Pass $id
            success : function(data){
            $('.fetched-data').html(data);//Show fetched data from database
            }
        });
     });
}); 

Php (readDetails.php)

 $conn = new PDO('**dados da conexão**'); 


//Include database connection
if($_POST['rowid']) {
   $id = $_POST['rowid']; //escape string
    // Run the Query
    // Fetch Records
    // Echo the data you want to show in modal


             $sql = $conn->prepare( "SELECT * FROM Pedidos WHERE id = $id");
             $sql->execute();
            $result = $sql->fetch(PDO::FETCH_ASSOC);


 }
    
asked by anonymous 13.07.2016 / 15:45

1 answer

-1

Change ajax to:

$.ajax({
    ...
    data : { rowid : rowid },
    ...
})
    
13.07.2016 / 18:40