php sql delete button

岁酱吖の 提交于 2019-12-04 17:47:46

You will need to make your links pass a param to a script that will delete that record. Your links would looks something like this

 echo "<a href=\"'delete.php?id=" . $user_id"\">" . $row['city'] . "</a>";

Then your delete can just grab the params from the $_GET gloabal, and pass them into your sql like so

  $del = mysql_query("DELETE FROM camps WHERE user_id=" . $_GET['user_id']);

This current query will delete all camps for that user (adjust params / sql as needbe).

However, you should NEVER pass user vars into your sql strings. You leave yourself open for sql injection attacks. I would recommend using PDO to escape your sql. I would also recommend using the post method for any destructive db operation so that you don't accidentally alter something.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!