Delete table record in php











up vote
0
down vote

favorite












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 at 14:08






  • 3




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












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










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










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















up vote
0
down vote

favorite












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 at 14:08






  • 3




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












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










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










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













up vote
0
down vote

favorite









up vote
0
down vote

favorite











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 at 14:12

























asked Nov 19 at 14:06









Bruno

165




165












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






  • 3




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












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










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










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


















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






  • 3




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












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










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










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
















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




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




3




3




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






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














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




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












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




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












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




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












1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










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',
    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








    up vote
    0
    down vote



    accepted










    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

























      up vote
      0
      down vote



      accepted










      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























        up vote
        0
        down vote



        accepted







        up vote
        0
        down vote



        accepted






        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 at 14:50









        manelseo

        1124




        1124






























             

            draft saved


            draft discarded



















































             


            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

            404 Error Contact Form 7 ajax form submitting

            How to know if a Active Directory user can login interactively

            TypeError: fit_transform() missing 1 required positional argument: 'X'