我正在尝试在我的数据库中选择最后一次id更新,现在我想删除此id,但它没有执行命令。
这是我的代码:
if(isset($_GET['delete'])){
$delete_id = sanitize($_GET['delete']);
$db->query("DELETE * FROM transactions WHERE id = (SELECT MAX(id) FROM transactions)");
echo $delete_id;
$_SESSION['success_flash']='El pedido se canceló correctamente';
}
$query = $db->query("SELECT * FROM transactions WHERE id = (SELECT MAX(id) FROM transactions)");
$cart = mysqli_fetch_assoc($query);
$cart_id = sanitize($cart['cart_id']);
<a href="confirmacion.php?delete=<?=$cart_id;?>" class="btn btn-default btn-xs float-right">Cancelar</a>
在echo $delete_id
中,我得到了正确的值。
这个问题太愚蠢......我只是意识到交易的id与MAX id不同,而是cart_id。所以实际值是cart_id no id。我只是修改FROM值。坏:
$db->query("DELETE * FROM transactions WHERE id = (SELECT MAX(id) FROM transactions)");
正确:
$db->query("DELETE * FROM transactions WHERE cart_id = $cart_id");
无论如何希望我会得到一个更好的安全脚本。与此同时,我正在学习。谢谢!