Php SQL的删除按钮

Php SQL的删除按钮,php,mysql,Php,Mysql,我有一个会员/帐户站点,可以发布“备注”并将其保存在您的帐户中。当有人发布一个便笺时,每个便笺都会得到一个编辑和一个删除按钮。我想删除按钮删除相应的职位,但它删除任何注意是在顶部。我假设当按下delete按钮或创建按钮时,问题在else中。我不需要一种方法来为按钮分配一个id吗 提前谢谢 <!-- connections.php connects to the database --> <?php require 'connections.php'; ?> <!-

我有一个会员/帐户站点,可以发布“备注”并将其保存在您的帐户中。当有人发布一个便笺时,每个便笺都会得到一个编辑和一个删除按钮。我想删除按钮删除相应的职位,但它删除任何注意是在顶部。我假设当按下delete按钮或创建按钮时,问题在else中。我不需要一种方法来为按钮分配一个id吗

提前谢谢

<!-- connections.php connects to the database -->
<?php require 'connections.php'; ?>

<!-- check to make sure the user is logged in,
     if not then redirect them to login.php -->
<?php session_start();
if(isset($_SESSION["UserID"])){ 
} else {
    header('Location: Login.php');
    die();
}?>

<!-- $result is a query containing all the notes
     of the current user -->
<?php $UserID = $_SESSION["UserID"];
      $result = mysqli_query($con, "SELECT * FROM notes WHERE UserID = '$UserID'");    
?>

<!-- when you click 'save' upload the new note 
     to the database and refresh the page.
     when you click 'delete' remote the note
     that goes with that button from the database -->
<?php  if(isset($_POST['save'])) {

        session_start();
        $note = $_POST['note'];
        $UserID = ($_SESSION["UserID"]);

        $sql = $con->query("INSERT INTO notes (UserID, note)Values('{$UserID}','{$note}')");

        header('Location: Account.php');

    } else if (isset($_POST['delete'])){
        $result = mysqli_query($con, "SELECT * FROM notes WHERE UserID = '$UserID'");
        $row = mysqli_fetch_array($result);
        $noteID = $row['noteID'];
        $UserID = ($_SESSION["UserID"]);

        $sql = $con->query("DELETE FROM notes WHERE noteID = '$noteID'");

        header('Location: Account.php');

    } else if (isset($_POST['edit'])){


}?>

<!DOCTYPE HTML>
<html lang="en">
    <head>
        <title>My Account</title>
        <link rel="stylesheet" type="text/css" href="stylesheet.css">
    </head>

    <body>

        <h1 class="titleAct">Welcome</h1> 

        <form action="" method="post" name="notesubmit" id="notesubmit">

                <div>
                    <textarea name="note" cols="50" rows="4" form="notesubmit" id="noteinput">New Note
                    </textarea>   
                </div>

                    <input name="save"  type="submit" class="button" id="save" value="Save">  

            <!-- Whenever a note is saved, print out the
                 note with timestamp followed by the edit
                 and delete buttons for each note -->
            <?php while ($row = mysqli_fetch_array($result)): ?>
                <?php $note = $row['note'];?>
                <?php $date = $row['time'];?>

        <div id="note">
            <p class="note"><?php echo $date; ?></br> ---------------- </br><?php echo $note; ?></p>
        </div>

                <input name="edit"  type="submit" class="button" id="edit" value="Edit">
                <input name="delete"  type="submit" class="button" id="delete" value="Delete">

            <?php endwhile; ?>
        </form>

        <div>
            <a class="link" href="Logout.php">Logout</a>
            <div>
            <a class="link" href="Deactivate.php">Deactivate My Account</a>
            </div>
        </div>

    </body>
</html>


你有一个逻辑错误。。。您没有将要删除的便笺的ID发回任何地方,您只是说您要删除某些内容,然后从数据库中获取便笺列表,并删除第一个弹出的便笺

我要做的是,将删除按钮更改为链接,并设置查询参数(
$\u GET['noteID']
)以选择要删除的ID

然后我会从数据库中选择NoteID,但也要确保用户尝试删除自己的帖子,而不是其他人的帖子

祝你好运:)