Update & delete MySQL from modal bootstrap
<p>I´m trying to delete and/or update data from form inside a modal window .For create it I haven´t problem but with the others actions (delete and update) I always have a problem,I think the key is the "id" it seems take the last value and not the value that I want to delete or update.
I know my code could be more nice.</p>

<pre><code>   &lt;div class="container"&gt;

        &lt;div class="row espacio"&gt;
                &lt;p class="col-md-1"&gt;&lt;a data-toggle="modal" href="#myModal" class="btn btn-default glyphicon glyphicon-plus"&gt;&lt;span&gt;&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;
            &lt;p class="col-md-1 col-md-offset-10"&gt;&lt;span class="btn btn-default glyphicon glyphicon-envelope"&gt;&lt;a href=""&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
            &lt;table class="table  table-bordered"&gt;
                &lt;caption&gt;Bitácora&lt;/caption&gt;
                &lt;thead&gt;
                    &lt;tr&gt;
                      &lt;th&gt;Tecnico&lt;/th&gt;
                      &lt;th&gt;Turno&lt;/th&gt;
                      &lt;th&gt;Información&lt;/th&gt;
                      &lt;th&gt;Estado&lt;/th&gt;
                      &lt;th&gt;Creada&lt;/th&gt;
                      &lt;th&gt;Modificada&lt;/th&gt;
                    &lt;/tr&gt;
                &lt;/thead&gt;
              &lt;tbody&gt;

                &lt;?php
                  $txt ="";
                  $nombres =array();
                  $turnos = array('Mañana','Tarde','Noche');
                  $estados =array('Pendiente','Cerrado');
                  $db = new Db;
                  $sql = "SELECT * FROM tecnicos";
                  foreach ($db-&gt;consulta($sql) as $row) {
                      array_push($nombres,$row['Nombre']);
                  }
                  $sql = 'SELECT * FROM bitacora ORDER BY Estado DESC';
                  $consulta = $db-&gt;consulta($sql);
                  while ($row = mysqli_fetch_array($consulta)) {
                        $tecnico = $turno = $estado = "";
                        if ($row['Estado'] == "Pendiente"){
                          $txt .= "&lt;tr class= 'bg-warning'&gt;";
                        }else{
                          $txt .= "&lt;tr class= 'bg-success'&gt;";
                        }
                        $txt .= "
                                &lt;td&gt;". $row['Name'] . "&lt;/td&gt;
                                &lt;td&gt;". $row['Turno'] . "&lt;/td&gt;
                                &lt;td&gt;". $row['Info'] . "&lt;/td&gt;
                                &lt;td&gt;". $row['Estado'] . "&lt;/td&gt;
                                &lt;td&gt;". $row['RecordDate'] . "&lt;/td&gt;
                                &lt;td&gt;". $row['ModiDate'] . "&lt;/td&gt;
                                &lt;td class='text-center'&gt;&lt;a data-toggle='modal' href='#myModalUpdate".$row['Id']."''&gt;&lt;span class='glyphicon glyphicon-pencil'&gt;&lt;/span&gt;&lt;/a&gt;
                                &lt;a data-toggle='modal' href='#myModalDelete".$row['Id']."''&gt;&lt;span class='glyphicon glyphicon-remove'&gt;&lt;/span&gt;&lt;/a&gt; &lt;/td&gt;
                              &lt;/tr&gt;";


                        //MODAL UPDATE

                        for ($i=0; $i &lt;sizeof($nombres) ; $i++) { 
                            if ($nombres[$i] == $row['Name'] ) {
                                $tecnico .= '&lt;option value="'.$nombres[$i].'" selected="selected"&gt;'.$nombres[$i].'&lt;/option&gt;';
                            }
                            else{
                                $tecnico .= '&lt;option value="'.$nombres[$i].'" &gt;'.$nombres[$i].'&lt;/option&gt;';
                            }
                        }

                        for ($i=0; $i &lt;sizeof($turnos) ; $i++) { 
                            if ($turnos[$i] == $row['Turno']) {
                                $turno .= '&lt;option value="'.$turnos[$i].'" selected="selected"&gt;'.$turnos[$i].'&lt;/option&gt;';
                            }
                            else{
                                $turno .= '&lt;option value="'.$turnos[$i].'" &gt;'.$turnos[$i].'&lt;/option&gt;';
                            }
                        }

                        for ($i=0; $i &lt;sizeof($estados) ; $i++) { 
                            if ($estados[$i] == $row['Estado']) {
                                $estado .= '&lt;option value="'.$estados[$i].'" selected="selected"&gt;'.$estados[$i].'&lt;/option&gt;';
                            }
                            else{
                                $estado .= '&lt;option value="'.$estados[$i].'" &gt;'.$estados[$i].'&lt;/option&gt;';
                            }
                        }

                        $txt .= " &lt;div class='modal fade' id='myModalUpdate".$row['Id']."' role='dialog'&gt;
                                    &lt;div class='modal-dialog'&gt;
                                      &lt;!-- Modal content--&gt;
                                      &lt;div class='modal-content'&gt;
                                          &lt;div class='modal-header'&gt;
                                            &lt;button type='button' class='close' data-dismiss='modal'&gt;&amp;times;&lt;/button&gt;
                                            &lt;h4 class='modal-title'&gt;Modifica registro en Bitácora&lt;/h4&gt;
                                          &lt;/div&gt;
                                          &lt;div class='modal-body'&gt;
                                            &lt;form role='form' action='' method='post'&gt;
                                              &lt;div class='form-group'&gt;
                                                  &lt;input type='text' name='id' value='".$row['Id']."'&gt;
                                              &lt;/div&gt;
                                              &lt;div class='form-group'&gt;
                                                  &lt;label&gt;Técnico&lt;/label&gt;
                                                  &lt;select class='form-control' name='modnombre'&gt;
                                                      ".$tecnico."
                                                  &lt;/select&gt;
                                              &lt;/div&gt;
                                              &lt;div class='form-group'&gt;
                                                  &lt;label&gt;Turno&lt;/label&gt;
                                                  &lt;select class='form-control' name='modturno'&gt;
                                                      ".$turno."
                                                   &lt;/select&gt;
                                              &lt;/div&gt;
                                              &lt;div class='form-group'&gt;
                                                  &lt;label&gt;Información&lt;/label&gt;
                                                  &lt;textarea class='form-control' name='modinformacion'&gt;".$row['Info']."&lt;/textarea&gt;
                                              &lt;/div&gt;
                                              &lt;div class='form-group'&gt;
                                                  &lt;label&gt;Estado&lt;/label&gt;
                                                  &lt;select class='form-control' name='modestado'&gt;
                                                      ".$estado."
                                                  &lt;/select&gt;
                                              &lt;/div&gt;
                                              &lt;div class='form-group text-center'&gt;
                                                  &lt;button type='submit' class='btn btn-warning' name='actualizar'&gt;Actualiza&lt;/button&gt;
                                              &lt;/div&gt;
                                          &lt;/div&gt;&lt;!--/modal body--&gt;
                                          &lt;div class='modal-footer'&gt;
                                            &lt;button type='button' class='btn btn-default' data-dismiss='modal'&gt;Close&lt;/button&gt;
                                          &lt;/div&gt;
                                      &lt;/div&gt;&lt;!--/modal content--&gt;
                                  &lt;/div&gt;&lt;!--/modal dialog--&gt;
                                &lt;/div&gt;&lt;!--/modal--&gt;";

                        //MODAL DELETE

                        $txt .= " &lt;div class='modal fade' id='myModalDelete".$row['Id']."' role='dialog' &gt;
                                    &lt;div class='modal-dialog'&gt;
                                      &lt;!-- Modal content--&gt;
                                      &lt;div class='modal-content'&gt;
                                          &lt;div class='modal-header'&gt;
                                            &lt;button type='button' class='close' data-dismiss='modal'&gt;&amp;times;&lt;/button&gt;
                                            &lt;h4 class='modal-title'&gt;Elemina registro en Bitácora&lt;/h4&gt;
                                          &lt;/div&gt;
                                          &lt;div class='modal-body'&gt;
                                            &lt;form role='form' action='' method='post'&gt;
                                              &lt;div class='form-group'&gt;
                                                  &lt;input type='text' name='id' value='".$row['Id']."'&gt;
                                              &lt;/div&gt;
                                              &lt;div class='form-group text-center'&gt;
                                                  &lt;button type='submit' class='btn btn-danger' name='eliminar'&gt;Elimina&lt;/button&gt;
                                              &lt;/div&gt;
                                          &lt;/div&gt;&lt;!--/modal body--&gt;
                                          &lt;div class='modal-footer'&gt;
                                            &lt;button type='button' class='btn btn-default' data-dismiss='modal'&gt;Close&lt;/button&gt;
                                          &lt;/div&gt;
                                      &lt;/div&gt;&lt;!--/modal content--&gt;
                                  &lt;/div&gt;&lt;!--/modal dialog--&gt;
                                &lt;/div&gt;&lt;!--/modal--&gt;";


                }//end for principal
                echo $txt;
                ?&gt;

              &lt;/tbody&gt;
        &lt;/table&gt;
    &lt;/div&gt;

    &lt;!--MODAL CREATE--&gt;
    &lt;div class="modal fade" id="myModal" role="dialog"&gt;
        &lt;div class="modal-dialog"&gt;
            &lt;!-- Modal content--&gt;
            &lt;div class="modal-content"&gt;
                &lt;div class="modal-header"&gt;
                    &lt;button type="button" class="close" data-dismiss="modal"&gt;&amp;times;&lt;/button&gt;
                    &lt;h4 class="modal-title"&gt;Añade registro en Bitácora&lt;/h4&gt;
                &lt;/div&gt;
                &lt;div class="modal-body"&gt;
                    &lt;form role="form" action="" method="post"&gt;
                        &lt;div class="form-group"&gt;
                            &lt;label&gt;Técnico&lt;/label&gt;
                            &lt;select class="form-control" name="nombre"&gt;
                                &lt;?php
                                    $txt ="";
                                    $db = new Db;
                                    $sql = "SELECT * FROM tecnicos";
                                    foreach ($db-&gt;consulta($sql) as $row) {
                                        $txt.= "&lt;option value='".$row['Nombre']."'&gt;".$row['Nombre']."&lt;/option&gt;";
                                    }
                                    echo $txt;
                                ?&gt;
                            &lt;/select&gt;
                        &lt;/div&gt;
                        &lt;div class="form-group"&gt;
                            &lt;label&gt;Turno&lt;/label&gt;
                            &lt;select class="form-control" name="turno"&gt;
                                &lt;option value="Mañana"&gt;Mañana&lt;/option&gt;
                                &lt;option value="Tarde"&gt;Tarde&lt;/option&gt;
                                &lt;option value="Noche"&gt;Noche&lt;/option&gt;
                            &lt;/select&gt;
                        &lt;/div&gt;
                        &lt;div class="form-group"&gt;
                            &lt;label&gt;Información&lt;/label&gt;
                            &lt;textarea class="form-control" name="informacion"&gt;&lt;/textarea&gt;
                        &lt;/div&gt;
                        &lt;div class="form-group text-center"&gt;
                            &lt;button type="submit" class="btn btn-success" name="crear"&gt;Crear&lt;/button&gt;
                        &lt;/div&gt;
                    &lt;/form&gt;
                &lt;/div&gt;&lt;!--/modal body--&gt;
                &lt;div class="modal-footer"&gt;
                    &lt;button type="button" class="btn btn-default" data-dismiss="modal"&gt;Close&lt;/button&gt;
                &lt;/div&gt;
            &lt;/div&gt;&lt;!--/modal content--&gt;
        &lt;/div&gt;&lt;!--/modal dialog--&gt;
    &lt;/div&gt;&lt;!--/modal--&gt;







&lt;/div&gt; &lt;!-- /container --&gt;
</code></pre>

<p>And these are the action´s form</p>

<pre><code>enter code //formulario CREATE
if(isset($_POST["crear"])) {
    $nombre = $_POST["nombre"];
    $turno = $_POST["turno"];
    $informacion = $_POST["informacion"];
    $sql = "INSERT INTO bitacora (Name,Turno,Info,Estado,RecordDate,ModiDate) VALUES ('" . $nombre . "', '" . $turno . "', '" . $informacion . "','Pendiente',now(),now())";
    $db-&gt;consulta($sql);
}
</code></pre>

<p>//formulario UPDATE</p>

<pre><code>if(isset($_POST["actualizar"])) {
    $sql = "UPDATE bitacora SET Name = '" . $_POST["modnombre"] . "', Turno = '" . $_POST["modturno"] . "', Info = '" .$_POST["modinformacion"]. "',  Estado = '" . $_POST["modestado"] . "' , ModiDate =now() WHERE Id = '".$_POST["id"]."' ";
    $db-&gt;consulta($sql);
}
</code></pre>

<p>//form DELETE</p>

<pre><code>if(isset($_POST["eliminar"])) {
    $id = $_POST["id"];
    $sql = "DELETE FROM bitacora WHERE Id = $id";
    $db-&gt;consulta($sql);
}here
</code></pre>