删除查询不起作用

时间:2016-03-23 12:10:15

标签: php pdo

我做了删除查询。删除查询用于删除管理员发布的帖子但是如果我点击删除按钮,我会转到没有找到对象的屏幕。 我将显示删除查询:

    include '../db/db.php';

$id = $_GET['0'];

$query = "DELETE FROM pages WHERE paginaNummer = :id";
$stmt = $dbcon->prepare($query);
$stmt->execute(array(':id' => $id));
$row=$stmt->fetch();

header("Location: http://127.0.0.1/cmsFenB/index.php");

这是数据库连接:

<?php

try {
    $db = new PDO('mysql:host=localhost;dbname=register', 'root', '');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}   catch(PDOException $e) {
    echo $e->getMessage();
    die();
}
?>

以下是引用此脚本的链接:

echo "&nbsp;<a class='delete' href='fucntions/admin/delete.php?id=" . $pageNumber . " '>Delete</a>"; 

我希望你能解决这个问题。

1 个答案:

答案 0 :(得分:0)

您在引荐来源链接中有拼写错误。它应该是这样的:

echo "&nbsp;<a class='delete' href='functions/admin/delete.php?id=" . $pageNumber . " '>Delete</a>"; 

$id=$_GET['0'];?我认为你的意思是$_GET['id']

$id=$_GET['id'];

$query = "DELETE FROM pages WHERE paginaNummer = :id";
$stmt = $db->prepare($query);
$stmt->execute(array(':id' => $id));