从html页面删除mysql行的最佳方法

编程入门 行业动态 更新时间:2024-10-23 07:15:50
本文介绍了从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行的最佳方法

本文发布于:2023-11-01 18:26:33,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:页面   方法   html   mysql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!