无法使用php从网站删除一行

时间:2017-11-02 15:10:57

标签: php

你好我用php mysqli程序语言制作Crud应用程序。我能够检索和插入数据但无法删除。当我点击删除链接时,它会进入delete.php页面,但没有任何反应。 db.php中

<?php
$conn = mysqli_connect('localhost', 'root','123','app');

?>

的index.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>CRUD</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>
</head>
<body>

    <table class="table table-bordered ">
    <tr>
    <th>id</th>
    <th>Email</th>
    <th>Fisrtname</th>
    <th>Lastname</th>
    <th>Delete</th>
    <th>Edit</th>
  </tr>
    <?php
include 'db.php';
$query ="select *from people";
    $result = mysqli_query($conn,$query);
    while($row = mysqli_fetch_assoc($result)){

?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['email']; ?></td>
<td><?php echo $row['firstname']; ?></td>
<td><?php echo $row['lastname']; ?></td>
<td><a href='delete.php?id=<?php echo $row['id']; ?>'>Delete</a></td>
<td><a href='edit.php?id=<?php echo $row['id']; ?>'>Edit</a></td>

</tr>
<?php
}
?>
    <div class="container">
            <a href="add_records.php" class="btn btn-info"><i class="glyphicon glyphicon-plus"></i>&nbsp; Add Records</a>


        </div>

</body>

</html>

delete.php

<?php

include 'db.php';
if (isset($_GET('id'))) {
    $delete_id = $_GET['id'];
    $query = "delete from people where id = '$delete_id'";
    $run = mysqli_query($conn,$query);
    if ($run) {
        header("Location:index.php");
    }
}

?>

1 个答案:

答案 0 :(得分:0)

第4行的delete.php中有拼写错误。

GET数组中,您必须在键名称周围使用[]括号而不是()

if (isset($_GET['id'])) {...}