Delete table data with no need to reload page to update

Asked

Viewed 51 times

-2

I have a table with data of a certain equipment, above the table has a field where the equipment number is inserted and quantity, the other information comes from the bank through the equipment number. In the last column of each table there is a button to delete this row, but for the effect to occur it is necessary to reload the page. But after the user does Submit 1x, when the page is reloaded, the browser understands the action as if there had been another Submit, that is, it inserts again the last inserted product.

This is how the data is printed in the table

while ($result_info = mysql_fetch_array($sql_info))
    {
      $tabela .= '<tr>';
      $tabela .=    '<td>'.$result_info['cod_item'].'</td>';
      $tabela .=    '<td>'.$result_info['desc_item'].'</td>';
      $tabela .=    '<td>'.$result_info['unidade'].'</td>';
      $tabela .=    '<td>'.$result_info['quantidade'].'</td>';
      $tabela .=    '<td>'.$result_info['valor'].'</td>';
      $tabela .=    '<td><a onclick="needToConfirm = false;" style="margin-left: 30px;" title="Excluir" src="../../dist/icons/delete.png"></a></td>'; href="pecas_proposta_incluir_temp_del.php?id={$linhas["id_temp"]}"><img 
      $tabela .=    '</tr>';
    }
echo $tabela;

As you can view the data are concatenated into a variable, so that when the user inserts more than one item, templates of about writing the previous item he creates a new line.

In short, what I need is for the user to be able to delete only the specified item and to be updated on time without the need to reload the page. If anyone has tips on how to re-load the page without causing a Ubmit again, I’ll be grateful.

  • search about ajax

  • Use Ajax at this link for an example of how to make http://matheuspiscioneri.com.br/blog/ajax-e-php-para-actualizr-sem-refresh/

  • How is the database deleted and included? You need to make this differentiation in PHP if you are doing both on the same page. You need to send the page a value that differentiates one thing from the other.

  • The inclusion and exclusion at the moment is on the same page, which is required by the page where the data is printed. I’ve been thinking about what you said, create a page just to insert and another to delete that after executed return to the main page, this way will not be done to reload the main page.

  • I don’t think you need to. Change the parameters sent to the page: when you delete, send the id of the item in a different variable, for example, &excluir=56... in PHP vc makes conditional to check what is being sent and does the deletion.

1 answer

0

when you reload the page the browser understands the action as if there had been another Ubmit, ie, re-enter the last inserted product.

Classic error. You must create another PHP file to do the insertion, and after done, the user must be redirected to the previous page. That is, the PHP file that modifies the database should never be the same that shows the data on the screen to the user. That is MVC.

without the need to reload the page.

For this you can use the $.ajax or $.post of the plugin jQuery

Browser other questions tagged

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