从html页面删除mysql行的最佳方法 - 删除链接和php [英] Best way to delete mysql rows from html page - delete link and php

查看:101
本文介绍了从html页面删除mysql行的最佳方法 - 删除链接和php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用while语句和PHP返回表中的所有行。这些行表示项目列表。我希望在每个项目旁边包含删除链接,以便用户可以删除条目。我试图找出如何在PHP中使用它。任何人都可以帮我写脚本..我使用程序..而不是面向对象。
我在想这个链接会把用户带到一个流程页面并返回,但我不会事先知道这些条目,它们都是动态的,并且列表总是在变化。



提前致谢

解决方案

最佳和保存练习是使用复选框。谷歌不会将它们蜘蛛,用户不能轻易放入恶意代码,并且不会刷新每次删除的页面: HTML样本:

  while($ row = mysql_fetch_assoc($ items))
{
echo'< input name =delete [ '。$ row ['id']。']type =checkbox>';
}

PHP处理示例:

  $ delete = $ _POST ['delete']; 

foreach($ delete as $ id = $ value)
{
$ id = mysql_real_escape_string($ id);
mysql_query(DELETE FROM table_name WHERE id = $ id);

$ / code>

像这样的东西应该很好地完成这项工作


I'm returning all rows in a table with a while statement and PHP. the rows indicate a list of items. I'd like to include delete links next to each item so users can delete the entries. I'm trying to figure how to go about it in PHP. Can anyone help me write the script.. I'm using procedural.. not OOP. I'm thinking the link takes users to a process page and back, but I'm not gonna be aware of the entries beforehand, it's all dynamic and the list is always changing.

thanks in advance

解决方案

Best and save practice is using checkboxes. Google doesn't spider them, users can't put in malicious code easily and it doesn't refresh the page for every delete:

HTML sample:

while ($row = mysql_fetch_assoc($items))
{
    echo '<input name="delete['.$row['id'].']" type="checkbox">';
}

PHP processing sample:

$delete = $_POST['delete'];

foreach($delete as $id = $value)
{
    $id = mysql_real_escape_string($id);
    mysql_query("DELETE FROM table_name WHERE id = $id");
}

Something like this should do the job nicely

这篇关于从html页面删除mysql行的最佳方法 - 删除链接和php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆