Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

95
Visualizações
Button to remove table row is not getting added to html table

I am trying to add a button to remove the table row when clicked. This should be placed next to data that is outputted from MySQL database.For some reason the button is not outputting, below is the code for my table:

<table>
                <thead>
                    <tr>
                        <th>Name</th>
                        <th>Email</th>
                        <th>Subject</th>
                        <th>Message</th>
                        <th>Have you replied?</th>
                    </tr>
                </thead>



                <?php //makes a connection to the database
                $conn = mysqli_connect("localhost", "root", "", "messages");
                if ($conn->connect_error) {
                    die("Connection Failed:" . $conn->connect_error);
                }

                $sql = "SELECT * FROM tbl_messages";
                $result = $conn->query($sql);


                if ($result->num_rows > 0) { //fills the table with the content in the database
                    while ($row = $result->fetch_assoc()) {
                        
                       echo '<tr><td>' . $row["name"] . '</td><td>' . $row["email"] . '</td><td>' . $row["subject"] . '</td><td>' . $row["message"] . '</td><td><button id="replied" onclick="DeleteRow()"></button>' . '</td></tr>';
                     
                    }

                    echo "</table";
                } else {
                    echo "0 result";
                }

                $conn->close();
                ?>

            </table>

And this is the javascript code to delete the table row:

    <script>
                function DeleteRow() {
                      
                      var td = event.target.parentNode; 
                     var tr = td.parentNode; // the row to be removed
                    tr.parentNode.removeChild(tr);
                }
    </script>

Picture of my table row The blank space underneath the "Have you replied" table header is where the button should be but its not there

I am still learning PHP so any replies on how I can fix this would be very helpful please

about 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda