如何在 PHP 中测试特定链接是否被点击

发布于 2024-11-27 08:39:53 字数 684 浏览 0 评论 0原文

我已经搜索这个问题的答案好几天了,我真的需要一个答案。 所以..我有一个数据库和一个从数据库获取数据的脚本:

while ($row = mysql_fetch_array ($query))
    {
        $name = $row['name'];
        $email = $row['email'];
        $tut_title = $row['tut_title'];
        $URL = $row['URL'];
        $description = $row ['description'];
        $Status = $row['Status'];
            echo "<tr>....<form action="samepage.php"><input type="submit"></form>
                ....

当单击提交表单时,正在加载同一页面并出现 if(isset $POST['submit']) 指令。 发生此操作时,我需要从数据库中删除该特定记录。 (仅存储最后一个条目的数据)

所以我需要在那段时间内的某个地方存储该特定记录的数据,这样我就可以用它来删除..我不知道你是否可以从头到尾我的请求,但我会回答你的任何问题,因为我真的不知道如何更好地解释它。

提前非常感谢你们。

I ve searched the answer to this question for days and I really need an answer..
so.. I have a database and a script that fetches the data from the database:

while ($row = mysql_fetch_array ($query))
    {
        $name = $row['name'];
        $email = $row['email'];
        $tut_title = $row['tut_title'];
        $URL = $row['URL'];
        $description = $row ['description'];
        $Status = $row['Status'];
            echo "<tr>....<form action="samepage.php"><input type="submit"></form>
                ....

When clicked the submit form, same page is being loaded and an if(isset $POST['submit']) instruction comes up.
When this action occurs, I need to delete that specific record from the database.
(only data for the last entry will be stored)

So I need to store the data for that specific record somewhere inside that while, so I can use it to delete.. I don't know if you can make heads and tails out of my request but I will answer to any of your questions because I really don't know how to explain it better.

Thank you so much in advance guys.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

深海不蓝 2024-12-04 08:39:53

该记录应该有一个 AUTO_INCRMENT 主键 - 我们称之为 $id

您将该标识符添加到表单中:

echo '<form action="samepage.php?id=' . $id . '">';

如前所述,您使用 isset() 检查是否使用了提交按钮。您可以使用 $_GET['id'] 获取标识符并构建 DELETE 查询。

The record should have an AUTO_INCREMENT primary key - let's call it $id.

You add that identifier to the form:

echo '<form action="samepage.php?id=' . $id . '">';

You, as already said, check for the submit button being used using isset(). You there can fetch the identifier using $_GET['id'] and construct a DELETE query.

孤君无依 2024-12-04 08:39:53

如果您有一个数据库并且您已经搜索并显示了一些值,并且当我单击与此元素关联的超链接时您想要删除一些特定值,那么可以使用此代码。

喜欢 :

Bk_name----Bk_Author   
C++         Y.V        Delete   
JAVA        Dietel     Delete
 .           .         .
 .           .         .

while( $info = mysql_fetch_assoc( $rs))
{
 echo" <a  href=task.php?delete=$info[bk_id]>Delete</a>";
 }
  //Now here on Hyperlink click event we will delete the associated data.

  if(isset($_REQUEST['delete']))
  {
   $delete = $_REQUEST['delete'];
   $query = mysql_query("DELETE FROM book WHERE bk_id= '$delete'")or   die(mysql_error());
   echo "Deleted";
}

Lets if you have a data base and you have searched out and display some value and You want to delete some specific value when i clicked on hyper link associated with this element then use this code.

like :

Bk_name----Bk_Author   
C++         Y.V        Delete   
JAVA        Dietel     Delete
 .           .         .
 .           .         .

while( $info = mysql_fetch_assoc( $rs))
{
 echo" <a  href=task.php?delete=$info[bk_id]>Delete</a>";
 }
  //Now here on Hyperlink click event we will delete the associated data.

  if(isset($_REQUEST['delete']))
  {
   $delete = $_REQUEST['delete'];
   $query = mysql_query("DELETE FROM book WHERE bk_id= '$delete'")or   die(mysql_error());
   echo "Deleted";
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文