我认为您的问题是您的表单操作(teams.php)将收到帖子数据.您的删除代码在同一个文件上,逻辑上$ _POST ['leave']将永远不会在此页面中设置.
只是尝试在您的表单操作属性中删除您的teams.php.
或者在teams.php文件中添加删除代码
//Make sure you have started the session before using it $user_id = $_SESSION['user_session']; if(isset($_POST['leave'])){ $stmt = $DB_con->prepare("DELETE FROM users WHERE user_id = $user_id "); $stmt->execute(); }
另一条建议是使用参数化查询.例:
if(isset($_POST['leave'])){ $stmt = $DB_con->prepare("DELETE FROM users WHERE user_id = ? "); $stmt-> bindParam(1,$user_id); $stmt->execute(); }