删除 link 与哈希比较 mysql 单元格
Delete link with hash compare to mysql cell
我希望用户能够从 link 中删除他的预订时间,方法是给他一个直接的 link 和 hash for ex.
http://example.org/delete.php?=a8df5b232f5ed38c9574ecbd0c248feccc968e83
我想将此哈希值 (a8df5b232f5ed38c9574ecbd0c248feccc968e83) 与添加到 dB(此订单)的这个哈希值进行比较,如果它们匹配,则删除记录。
这是我为生成散列并将其添加到我的 dB
所做的代码
$createDeleteHash = $getLastId['id'] . $nazwisko;
$deleteHash = sha1($createDeleteHash);
$stmt3 = $db->exec("UPDATE `order` SET delete_hash='$deleteHash' WHERE id='$getLastId[id]'");
首先您需要更改您发送的url:
http://example.org/delete.php?=a8df5b232f5ed38c9574ecbd0c248feccc968e83
给以下
http://example.org/delete.php?id=a8df5b232f5ed38c9574ecbd0c248feccc968e83
注意散列前面的 id
。这允许您使用 $_GET['id']
.
获取 GET 变量
所以在您的 delet.php 页面上,您需要这样的东西:
$sql="DELETE FROM order WHERE delete_hash = ':hash'";
$sth = $dbh->prepare($sql);
$sth->bindParam(':hash', $_GET['id'], PDO::PARAM_STR, 100);
$sth->execute();
这将从 table 中删除散列。所以你可能想把execute包裹在一个if中,这样你就可以在页面上发送消息,即删除或不删除等
我希望用户能够从 link 中删除他的预订时间,方法是给他一个直接的 link 和 hash for ex.
http://example.org/delete.php?=a8df5b232f5ed38c9574ecbd0c248feccc968e83
我想将此哈希值 (a8df5b232f5ed38c9574ecbd0c248feccc968e83) 与添加到 dB(此订单)的这个哈希值进行比较,如果它们匹配,则删除记录。
这是我为生成散列并将其添加到我的 dB
所做的代码$createDeleteHash = $getLastId['id'] . $nazwisko;
$deleteHash = sha1($createDeleteHash);
$stmt3 = $db->exec("UPDATE `order` SET delete_hash='$deleteHash' WHERE id='$getLastId[id]'");
首先您需要更改您发送的url:
http://example.org/delete.php?=a8df5b232f5ed38c9574ecbd0c248feccc968e83
给以下
http://example.org/delete.php?id=a8df5b232f5ed38c9574ecbd0c248feccc968e83
注意散列前面的 id
。这允许您使用 $_GET['id']
.
所以在您的 delet.php 页面上,您需要这样的东西:
$sql="DELETE FROM order WHERE delete_hash = ':hash'";
$sth = $dbh->prepare($sql);
$sth->bindParam(':hash', $_GET['id'], PDO::PARAM_STR, 100);
$sth->execute();
这将从 table 中删除散列。所以你可能想把execute包裹在一个if中,这样你就可以在页面上发送消息,即删除或不删除等