Delete table record in php












0














Within the while I created the delete button:



while($rows_cursos = mysqli_fetch_array($resultado_cursos)) {   
$tabela2 .= '<tr>';
$tabela2 .= '<td>'.$rows_cursos['IdEstado'].'</td>';
$tabela2 .= '<td>'.$rows_cursos['DataRequis'].'</td>';
$tabela2 .= '<td>'.$rows_cursos['Funcionario'].'</td>';
$tabela2 .= '<td><form action="./delete" method="post">';
$tabela2 .= '<input type="hidden" name="IdEstado" value="'.$rows_cursos['IdEstado'].'">';
$tabela2 .= '<button type="button" class="btn btn-danger">Excluir</button>'; //aqui está o seu botão
$tabela2 .= '</form></td>'; //só fechando o form
$tabela2 .= '</tr>';
}
$tabela2 .= '</tr>';
$tabela2 .='</tbody>';
$tabela2 .= '</table>';
$tabela2 .= '</div>';
echo $tabela2;


The action = "./delete" I put it this way because I'm working on wordpress and the action of this form is equal to action = "delete.php".



After deleting.php I have this code:



$id = $_POST['IdEstado'];

$sql = "DELETE FROM `centrodb`.`RequisicaoLuvas` WHERE `RequisicaoLuvas`.`id` = " . $id;
mysqli_query($conn,$sql) or die("Erro ao tentar cadastrar registro");
mysqli_close($conn);

$sql1 = "DELETE FROM `centrodb`.`EstadoLuvas` WHERE `EstadoLuvas`.`IdEstado` = " . $id;
mysqli_query($conn,$sql1) or die("Erro ao tentar cadastrar registro");
mysqli_close($conn);


When I click the delete button it does not delete anything in the database table.










share|improve this question
























  • what error do you get?
    – Prashanth Benny
    Nov 19 '18 at 14:08






  • 3




    Your button is a button and not a type="submit".
    – Demodave
    Nov 19 '18 at 14:09












  • @Prashanth Benny I am not receiving any errors, neither on the page nor in the chrome console
    – Bruno
    Nov 19 '18 at 14:09










  • @Demodave is going to delete.php page
    – Bruno
    Nov 19 '18 at 14:11










  • you could use die(mysqli_error($conn)); to display the exact error
    – Prashanth Benny
    Nov 19 '18 at 14:12
















0














Within the while I created the delete button:



while($rows_cursos = mysqli_fetch_array($resultado_cursos)) {   
$tabela2 .= '<tr>';
$tabela2 .= '<td>'.$rows_cursos['IdEstado'].'</td>';
$tabela2 .= '<td>'.$rows_cursos['DataRequis'].'</td>';
$tabela2 .= '<td>'.$rows_cursos['Funcionario'].'</td>';
$tabela2 .= '<td><form action="./delete" method="post">';
$tabela2 .= '<input type="hidden" name="IdEstado" value="'.$rows_cursos['IdEstado'].'">';
$tabela2 .= '<button type="button" class="btn btn-danger">Excluir</button>'; //aqui está o seu botão
$tabela2 .= '</form></td>'; //só fechando o form
$tabela2 .= '</tr>';
}
$tabela2 .= '</tr>';
$tabela2 .='</tbody>';
$tabela2 .= '</table>';
$tabela2 .= '</div>';
echo $tabela2;


The action = "./delete" I put it this way because I'm working on wordpress and the action of this form is equal to action = "delete.php".



After deleting.php I have this code:



$id = $_POST['IdEstado'];

$sql = "DELETE FROM `centrodb`.`RequisicaoLuvas` WHERE `RequisicaoLuvas`.`id` = " . $id;
mysqli_query($conn,$sql) or die("Erro ao tentar cadastrar registro");
mysqli_close($conn);

$sql1 = "DELETE FROM `centrodb`.`EstadoLuvas` WHERE `EstadoLuvas`.`IdEstado` = " . $id;
mysqli_query($conn,$sql1) or die("Erro ao tentar cadastrar registro");
mysqli_close($conn);


When I click the delete button it does not delete anything in the database table.










share|improve this question
























  • what error do you get?
    – Prashanth Benny
    Nov 19 '18 at 14:08






  • 3




    Your button is a button and not a type="submit".
    – Demodave
    Nov 19 '18 at 14:09












  • @Prashanth Benny I am not receiving any errors, neither on the page nor in the chrome console
    – Bruno
    Nov 19 '18 at 14:09










  • @Demodave is going to delete.php page
    – Bruno
    Nov 19 '18 at 14:11










  • you could use die(mysqli_error($conn)); to display the exact error
    – Prashanth Benny
    Nov 19 '18 at 14:12














0












0








0







Within the while I created the delete button:



while($rows_cursos = mysqli_fetch_array($resultado_cursos)) {   
$tabela2 .= '<tr>';
$tabela2 .= '<td>'.$rows_cursos['IdEstado'].'</td>';
$tabela2 .= '<td>'.$rows_cursos['DataRequis'].'</td>';
$tabela2 .= '<td>'.$rows_cursos['Funcionario'].'</td>';
$tabela2 .= '<td><form action="./delete" method="post">';
$tabela2 .= '<input type="hidden" name="IdEstado" value="'.$rows_cursos['IdEstado'].'">';
$tabela2 .= '<button type="button" class="btn btn-danger">Excluir</button>'; //aqui está o seu botão
$tabela2 .= '</form></td>'; //só fechando o form
$tabela2 .= '</tr>';
}
$tabela2 .= '</tr>';
$tabela2 .='</tbody>';
$tabela2 .= '</table>';
$tabela2 .= '</div>';
echo $tabela2;


The action = "./delete" I put it this way because I'm working on wordpress and the action of this form is equal to action = "delete.php".



After deleting.php I have this code:



$id = $_POST['IdEstado'];

$sql = "DELETE FROM `centrodb`.`RequisicaoLuvas` WHERE `RequisicaoLuvas`.`id` = " . $id;
mysqli_query($conn,$sql) or die("Erro ao tentar cadastrar registro");
mysqli_close($conn);

$sql1 = "DELETE FROM `centrodb`.`EstadoLuvas` WHERE `EstadoLuvas`.`IdEstado` = " . $id;
mysqli_query($conn,$sql1) or die("Erro ao tentar cadastrar registro");
mysqli_close($conn);


When I click the delete button it does not delete anything in the database table.










share|improve this question















Within the while I created the delete button:



while($rows_cursos = mysqli_fetch_array($resultado_cursos)) {   
$tabela2 .= '<tr>';
$tabela2 .= '<td>'.$rows_cursos['IdEstado'].'</td>';
$tabela2 .= '<td>'.$rows_cursos['DataRequis'].'</td>';
$tabela2 .= '<td>'.$rows_cursos['Funcionario'].'</td>';
$tabela2 .= '<td><form action="./delete" method="post">';
$tabela2 .= '<input type="hidden" name="IdEstado" value="'.$rows_cursos['IdEstado'].'">';
$tabela2 .= '<button type="button" class="btn btn-danger">Excluir</button>'; //aqui está o seu botão
$tabela2 .= '</form></td>'; //só fechando o form
$tabela2 .= '</tr>';
}
$tabela2 .= '</tr>';
$tabela2 .='</tbody>';
$tabela2 .= '</table>';
$tabela2 .= '</div>';
echo $tabela2;


The action = "./delete" I put it this way because I'm working on wordpress and the action of this form is equal to action = "delete.php".



After deleting.php I have this code:



$id = $_POST['IdEstado'];

$sql = "DELETE FROM `centrodb`.`RequisicaoLuvas` WHERE `RequisicaoLuvas`.`id` = " . $id;
mysqli_query($conn,$sql) or die("Erro ao tentar cadastrar registro");
mysqli_close($conn);

$sql1 = "DELETE FROM `centrodb`.`EstadoLuvas` WHERE `EstadoLuvas`.`IdEstado` = " . $id;
mysqli_query($conn,$sql1) or die("Erro ao tentar cadastrar registro");
mysqli_close($conn);


When I click the delete button it does not delete anything in the database table.







php html mysql






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 14:12

























asked Nov 19 '18 at 14:06









Bruno

166




166












  • what error do you get?
    – Prashanth Benny
    Nov 19 '18 at 14:08






  • 3




    Your button is a button and not a type="submit".
    – Demodave
    Nov 19 '18 at 14:09












  • @Prashanth Benny I am not receiving any errors, neither on the page nor in the chrome console
    – Bruno
    Nov 19 '18 at 14:09










  • @Demodave is going to delete.php page
    – Bruno
    Nov 19 '18 at 14:11










  • you could use die(mysqli_error($conn)); to display the exact error
    – Prashanth Benny
    Nov 19 '18 at 14:12


















  • what error do you get?
    – Prashanth Benny
    Nov 19 '18 at 14:08






  • 3




    Your button is a button and not a type="submit".
    – Demodave
    Nov 19 '18 at 14:09












  • @Prashanth Benny I am not receiving any errors, neither on the page nor in the chrome console
    – Bruno
    Nov 19 '18 at 14:09










  • @Demodave is going to delete.php page
    – Bruno
    Nov 19 '18 at 14:11










  • you could use die(mysqli_error($conn)); to display the exact error
    – Prashanth Benny
    Nov 19 '18 at 14:12
















what error do you get?
– Prashanth Benny
Nov 19 '18 at 14:08




what error do you get?
– Prashanth Benny
Nov 19 '18 at 14:08




3




3




Your button is a button and not a type="submit".
– Demodave
Nov 19 '18 at 14:09






Your button is a button and not a type="submit".
– Demodave
Nov 19 '18 at 14:09














@Prashanth Benny I am not receiving any errors, neither on the page nor in the chrome console
– Bruno
Nov 19 '18 at 14:09




@Prashanth Benny I am not receiving any errors, neither on the page nor in the chrome console
– Bruno
Nov 19 '18 at 14:09












@Demodave is going to delete.php page
– Bruno
Nov 19 '18 at 14:11




@Demodave is going to delete.php page
– Bruno
Nov 19 '18 at 14:11












you could use die(mysqli_error($conn)); to display the exact error
– Prashanth Benny
Nov 19 '18 at 14:12




you could use die(mysqli_error($conn)); to display the exact error
– Prashanth Benny
Nov 19 '18 at 14:12












1 Answer
1






active

oldest

votes


















0














You can do it easy with PDO and avoid SQL Inyection if you want to use mysqli you can do something similar. Follow this link: http://php.net/manual/es/mysqli-stmt.bind-param.php



<?php
$id = $_POST['IdEstado'];
$pdo = new PDO("mysql:host=" . $dataBaseHost . "; dbname=" . $dataBaseName . "", $dataBaseUserName, $dataBasePassword);
$prepared_statement = $pdo->prepare("DELETE FROM RequisicaoLuvas WHERE id=:id");
$prepared_statement->bindParam(':id', $id);
$prepared_statement->execute();
$pdo = null;
?>





share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53376378%2fdelete-table-record-in-php%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    You can do it easy with PDO and avoid SQL Inyection if you want to use mysqli you can do something similar. Follow this link: http://php.net/manual/es/mysqli-stmt.bind-param.php



    <?php
    $id = $_POST['IdEstado'];
    $pdo = new PDO("mysql:host=" . $dataBaseHost . "; dbname=" . $dataBaseName . "", $dataBaseUserName, $dataBasePassword);
    $prepared_statement = $pdo->prepare("DELETE FROM RequisicaoLuvas WHERE id=:id");
    $prepared_statement->bindParam(':id', $id);
    $prepared_statement->execute();
    $pdo = null;
    ?>





    share|improve this answer


























      0














      You can do it easy with PDO and avoid SQL Inyection if you want to use mysqli you can do something similar. Follow this link: http://php.net/manual/es/mysqli-stmt.bind-param.php



      <?php
      $id = $_POST['IdEstado'];
      $pdo = new PDO("mysql:host=" . $dataBaseHost . "; dbname=" . $dataBaseName . "", $dataBaseUserName, $dataBasePassword);
      $prepared_statement = $pdo->prepare("DELETE FROM RequisicaoLuvas WHERE id=:id");
      $prepared_statement->bindParam(':id', $id);
      $prepared_statement->execute();
      $pdo = null;
      ?>





      share|improve this answer
























        0












        0








        0






        You can do it easy with PDO and avoid SQL Inyection if you want to use mysqli you can do something similar. Follow this link: http://php.net/manual/es/mysqli-stmt.bind-param.php



        <?php
        $id = $_POST['IdEstado'];
        $pdo = new PDO("mysql:host=" . $dataBaseHost . "; dbname=" . $dataBaseName . "", $dataBaseUserName, $dataBasePassword);
        $prepared_statement = $pdo->prepare("DELETE FROM RequisicaoLuvas WHERE id=:id");
        $prepared_statement->bindParam(':id', $id);
        $prepared_statement->execute();
        $pdo = null;
        ?>





        share|improve this answer












        You can do it easy with PDO and avoid SQL Inyection if you want to use mysqli you can do something similar. Follow this link: http://php.net/manual/es/mysqli-stmt.bind-param.php



        <?php
        $id = $_POST['IdEstado'];
        $pdo = new PDO("mysql:host=" . $dataBaseHost . "; dbname=" . $dataBaseName . "", $dataBaseUserName, $dataBasePassword);
        $prepared_statement = $pdo->prepare("DELETE FROM RequisicaoLuvas WHERE id=:id");
        $prepared_statement->bindParam(':id', $id);
        $prepared_statement->execute();
        $pdo = null;
        ?>






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 19 '18 at 14:50









        manelseo

        1124




        1124






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53376378%2fdelete-table-record-in-php%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            Npm cannot find a required file even through it is in the searched directory