使用php和javascript更新和删除数据库表的每个项目的按钮

时间:2017-04-07 07:03:46

标签: javascript php html mysqli

我可以在数据库中轻松显示表格的项目,并创建删除和更新按钮。我想要的是当我按下项目的删除按钮,获取项目的ID然后从数据库中删除它但有些东西是不对的,我找不到它。当我按下项目的删除按钮时没有任何反应。这是我的代码:

PHP文件:

<body>

<?php
        $con = mysql_connect("localhost:3307", "root", "");
        mysql_select_db("seiis_notes", $con);
        $result = mysql_query("select * from tbl_notes"); 
?>

<table>
    <?php
        while($row = mysql_fetch_array($result))
        {
            ?>
            <div class="note_and_btns">
                <div class="noteDescription_editNote">
                        <form action="updateORdelete.php" method="post">
                        ID: <input type="text" name="id" value="<?php echo $row["NoteID"] ?>" readonly/>
                        <br/>
                        Description: <input type="text" name="projects" value="<?php echo $row["rel_projects"] ?>" readonly/>
                        <br/>
                        Creator: <input type="text" name="creator" value="<?php echo $row["note_creator"] ?>" readonly/>
                        <br/>
                        <input id="<?php echo $row["NoteID"] ?>" name="action" type="submit" value="Edit"/>
                        <input id="<?php echo $row["NoteID"] ?>" name="action" type="submit" value="Delete"/>
                        </form>
                </div>
            </div>
            <br/> <br/>
        <?php
        }
    ?>
    <br/><br/>

这是我的更新或删除文件:

<body>
    <?php

    $con = mysql_connect("localhost:3307", "root", "");
    mysql_select_db("seiis_notes", $con);

    if ($_POST['action'] == 'Delete') 
        {
                $value = $_POST["id"];
                mysqli_query($con, "delete from tbl_notes where id='$value'");
                echo "<script type='text/javascript'>alert('Deleted Succesfully');</script>";

        ?>
        <meta http-equiv="refresh" content="5;url=notes.html"/>
        <?php  
        }
        else if ($_POST['action'] == 'Edit')
        {
            //code to edit data
        }
    ?>
</body>

0 个答案:

没有答案