Button to delete record

Asked

Viewed 1,744 times

0

I have a page that shows the records made in a form.

When a register needs to be deleted, I need to access phpMyAdmin, preventing anyone other than me from deleting the record.

What I wanted:

I wanted to make a button that would delete the register positioned on the side, but I don’t know exactly where to put this button to get it in the position I want.

Matrix:

<h1 style="
    text-align: center;
    height: 7;
    margin-top: 150;
"> Consulta de turmas </h1>
<?php
//Conexão e consulta ao Mysql
mysql_connect('localhost','root','') or die(mysql_error());
mysql_select_db('db_formacao') or die(mysql_error());
$qry = mysql_query("select * from turmas");

//Pegando os nomes dos campos
$num_fields = mysql_num_fields($qry);//Obtém o número de campos do resultado

for($i = 0;$i<$num_fields; $i++){//Pega o nome dos campos
    $fields[] = mysql_field_name($qry,$i);
}

//Montando o cabeçalho da tabela
$table = '<table class="table table-hover table-inverse" style="margin-top:80;background-color: #37444a; color:lightgrey;"> <tr>';

for($i = 0;$i < $num_fields; $i++){
    $table .= '<th>'.$fields[$i].'</th>';
}

//Montando o corpo da tabela
$table .= '<tbody style="
    background-color: #86979e;
    color: #37444a;    
">';
while($r = mysql_fetch_array($qry)){
    $table .= '<tr>';
    for($i = 0;$i < $num_fields; $i++){
        $table .= '<td>'.$r[$fields[$i]].'</td>';
    }
    $table .= '</tr>';
}

//Finalizando a tabela
$table .= '</tbody></table>';

//Imprimindo a tabela
echo $table;

?>

Picture of the damned:

inserir a descrição da imagem aqui

  • 1

    1° tip, change the connection extension to bd, from mysql to mysqli or Pdo, the mysql extension is discontinued and is totally discouraged by the php community to continue using it

1 answer

0


You just need to add a new column in your table with the link/button inside the while, follow below your code with the change / example:

<h1 style="
    text-align: center;
    height: 7;
    margin-top: 150;
"> Consulta de turmas </h1>
<?php
//Conexão e consulta ao Mysql
mysql_connect('localhost','root','') or die(mysql_error());
mysql_select_db('db_formacao') or die(mysql_error());
$qry = mysql_query("select * from turmas");

//Pegando os nomes dos campos
$num_fields = mysql_num_fields($qry);//Obtém o número de campos do resultado

for($i = 0;$i<$num_fields; $i++){//Pega o nome dos campos
    $fields[] = mysql_field_name($qry,$i);
}

//Montando o cabeçalho da tabela
$table = '<table class="table table-hover table-inverse" style="margin-top:80;background-color: #37444a; color:lightgrey;"> <thead><tr>';

for($i = 0;$i < $num_fields; $i++){
    $table .= '<th>'.$fields[$i].'</th>';
}
$table .= '<td>Ação</td></thead>';

//Montando o corpo da tabela
$table .= '<tbody style="
    background-color: #86979e;
    color: #37444a;    
">';
while($r = mysql_fetch_array($qry)){
    $table .= '<tr>';
    for($i = 0;$i < $num_fields; $i++){
        $table .= '<td>'.$r[$fields[$i]].'</td>';
    }

    // Adicionando botão de exclusão
    $table .= '<td><a href="exemplo-excluir.php?id=xxx">Excluir</a></td>';

    $table .= '</tr>';
}

//Finalizando a tabela
$table .= '</tbody></table>';

//Imprimindo a tabela
echo $table;

?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.