How to change database values with dynamically created buttons in PHP
<p>I am dynamically creating html content with PHP and I am creating a button and when that button is clicked It should invoke a PHP script that will update the values of a column of a specific row in the database </p>

<p>Here is my code:</p>

<pre><code>&lt;?php
    session_start();

    if(!isset($_SESSION['id'])){
        header("Location: login.php");
    }else{
        require_once("mysqli_connect.php");

        $query = "SELECT * FROM markeri WHERE odobreno ='F'";

        $response = @mysqli_query($dbc,$query);

        if($response){
            echo "&lt;hr&gt;";
            while($row = mysqli_fetch_assoc($response)){
                echo "&lt;div align='center' id='markeri'&gt;&lt;h3&gt;Naziv: " . $row['naziv'] . "&lt;/h3&gt;";
                echo "&lt;h3&gt;Ulica: " . $row['ulica'] . "&lt;/h3&gt;";
                echo "&lt;h3&gt;Opis:&lt;/h3&gt;" . "&lt;p&gt;" . $row['opis'] . "&lt;/p&gt;";
                echo "&lt;h4&gt;Email: " . $row['email'] . "&lt;/h4&gt;";
                echo "&lt;img src='" . $row['link_slike'] . "' width='300px' /&gt;&lt;/br&gt;";
                echo "&lt;form action='update.php' method='POST'&gt;";
                echo "&lt;textarea rows='10' cols='30' maxlength='500' placeholder='Komentar' name='" . $row['marker_id'] . "'&gt;&lt;/textarea&gt;&lt;/br&gt;";
                echo "&lt;input type='button' value='Odobri' name='" . $row['marker_id'] . "b" . "' /&gt;&lt;/form&gt;&lt;hr&gt;";
            }
        }




    }


?&gt;
</code></pre>

<p>I tried something like making the name of the textarea equal to the marker_id in my database and making the name of the button the value of marker_id + the string "b" but I don't know how to call them on my update.php script. Usually when it is a normal case and when there is no dynamic content I know how to do it with <code>$_POST['name'];</code></p>

<p><strong>EDIT:</strong></p>

<p>I used AJAX to dynamically create the HTML as you told me but I've encountered another problem</p>

<pre><code>&lt;script&gt;
    function page_loaded(){
        jQuery.ajax({
            method: "GET",
            url: "get_data_dashboard.php",
            success: function(data){
                var markers = JSON.parse(data);
                for(var i = 0; i &lt; markers.length; i++){
                    var m = markers[i];
                    var markerHTML = "&lt;div class='marker'&gt;" +
                        "&lt;span id='naziv'&gt;Naziv zahtjeva: " + m.naziv + "&lt;/span&gt;&lt;/br&gt;" + 
                        "&lt;span id='ulica'&gt;Ulica: " + m.ulica + "&lt;/span&gt;&lt;/br&gt;" + 
                        "&lt;p id='opis'&gt;Opis:&lt;/br&gt;" + m.opis + "&lt;/p&gt;&lt;/br&gt;" + 
                        "&lt;span id='email'&gt;Email: " + m.email + "&lt;/span&gt;&lt;/br&gt;" + 
                        "&lt;img id='slika' src='" + m.link_slike + "' /&gt;" + "&lt;/br&gt;" + 
                        "&lt;textarea rows='5' cols='30' maxlength='500' id='t" + m.marker_id + "' placeholder='Komentar'&gt;" + "&lt;/textarea&gt;&lt;/br&gt;"
                        + "&lt;div class='buttons'&gt;&lt;a href='odobri_prijavu.php?id=" + m.marker_id + "'&gt;Odobri&lt;/a&gt;" +
                            "&lt;a href='izbrisi_prijavu.php?id=" + m.marker_id + "'&gt;Izbriši&lt;/a&gt;"  + "&lt;/div&gt;"  + 
                        "&lt;/div&gt;&lt;hr&gt;";

                    $('#content').append(markerHTML);
                }

            }
        })



    }
    $(document).ready(page_loaded());

&lt;/script&gt;
</code></pre>

<p>I tried to use buttons but I couldn't figure how to add event handlers to dynamically created buttons that will post a request via AJAX to some php script with the proper id as the value and the value of the textarea. So I used the anchor tag and I was able to send the id, but I can't send the value of the textarea because I don't know how to reference it and even if I referenced it, it will be NULL because its value is set to the anchor tag at the very beginning and I want to type in text in the textarea.  </p>