Modify and delete records from a PHP table

1

I have made the connection to my Database and I have a table that filters the records in real time with Ajax. I have added the delete and modify buttons but I can not make them work, I have tried several tutorials but most use Json. If anyone knows where I can find the solution or how to do it, I appreciate it.

This is the code:

<body>
<h1 class="text-center titulo">Vehiculos</h1>
<div class="container">
    <div class="row">
        <div class="panel panel-default panel-table">
            <div class="panel-heading">
                <div class="row">
                    <div class="col col-xs-6">
                        <div class="input-group"> <span class="input-group-addon">Buscar vehiculos</span>
                            <input id="filtrar" type="text" class="form-control" placeholder="Ingrese texto a buscar">
                        </div>
                    </div>
                </div>
            </div>
            <div class="panel-body">
                <table class="table table-striped table-bordered table-list">
                    <thead>
                        <tr>
                            <center>
                            <th ><em style="margin-left: 50%;" class="fa fa-cog"></em></th>
                            <th>Dominio</th>
                            <th>Marca</th>
                            <th>Modelo</th>
                            </center>
                        </tr>
                    </thead>
                    <tbody class="contenidobusqueda"> 
         <?php 

                //Guardamos en $query los datos de la consulta.
                //asi a $row en un array con los datos de $query

                $query = mysqli_query($conn, "SELECT dominio,marca,modelo FROM vehiculos");
                for($i=0; $i<mysqli_num_rows ($query); ++$i){   
                    $row = mysqli_fetch_row($query);
        ?>
                            <tr>

                                <td align="center">
                                    <a class="btn btn-default"><em class="fa fa-pencil"></em></a>
                                    <a class="btn btn-danger"><em class="fa fa-trash"></em></a>
                                </td>
                                <td>
                                    <?php echo $row[0];?>
                                </td>
                                <td>
                                    <?php echo $row[1];?>
                                </td>
                                <td>
                                    <?php echo $row[2];?>
                                </td>
                            </tr>
                            <?php } ?>
                    </tbody>
                </table>
            </div>
        </div>
        <div class="row">
            <div class="col-md-6 col-md-offset-3 text-right">
                <a class="btn btn-info" href="../vistas/principalAdmin.php">Volver</a>
            </div>
        </div>
    </div>

 

And I have a javascript that is to search that is jsbuscar to which I refer in the previous code

$(document).ready(function () {

        (function ($) {

            $('#filtrar').keyup(function () {

                var rex = new RegExp($(this).val(), 'i');
                $('.contenidobusqueda tr').hide();
                $('.contenidobusqueda tr').filter(function () {
                    return rex.test($(this).text());
                }).show();

            })

        }(jQuery));

    });
    
asked by merisavino 03.11.2016 в 05:43
source

1 answer

1

This question is very similar to one that I had already answered before, maybe it will help:

Remove blob with ajax, button inside modal

Basically what you have to do is the following:

  • Create your two buttons (Delete and Edit) with an onclick event, you can do it with jquery with the id of each button
  • In your function called from the onclick of the buttons you must send your information through ajax, I would recommend send an ID of the table
  • In your request $ .ajax you must put the url of your PHP page that will process the request
  • In your PHP page you process the information by obtaining the data that you sent from your table with the variables $ _POST, $ _REQUEST or $ _GET
  • I recommend you validate that this request always comes from your site since anyone could send requests from other sites and delete records.

        
    answered by 02.03.2017 в 01:53