mysqli删除

时间:2013-03-12 17:08:18

标签: php mysqli

<?php

    if (intval($_GET['page']) == 0) {
        redirect_to("staff.php");
    }

    $id = mysqli_prep($_GET['page']);



        $query3 = "DELETE FROM page WHERE id = {$id}, LIMIT 1";
        $result = mysqli_query($connection, $query3);
        if (mysqli_affected_rows($connection) == 1) {
            redirect_to("staff.php");
        } else {
            // Deletion Failed

            echo $id ."<br />" . $query3 . "<br />" . $result . "<p>Subject
           deletion failed.</p>";
            echo "<p>" . mysqli_error() . "</p>";
            echo "<a href=\"staff.php\">Return to Main Page</a>";
        }
      //  Keep on working Edit:2#
      mysqli_query($connection, "DELETE FROM pages WHERE id = 11 ");
     //- Works 
     Edit 3# 
       $id = $_GET['page'];
        echo "<p>" . $id ."</p>";
            $query3 ="DELETE FROM pages WHERE id = {$id} ";
                    mysqli_query($connection,$query3 );
                    // Still Works  -- YaY for working backwards
   // Edit #4 By "now it might be obvious what my error was "pages" not "page"
       // Thanks everyone - And thank you for telling me about the error page
        // My defense - newbie- Anyway Lesson from this - working backwards 
        // Takes a while, Error checking Fast!!!!!!
?>

启动并选择$ connection。 $ id已成功选中,$ page = $ id,但仍无效。 $ query 3似乎很好,但删除失败了。我不知道错误是什么。在此先感谢您的帮助。 -Josh编辑检查错误检查

4 个答案:

答案 0 :(得分:1)

ID后面有逗号:

$query3 = "DELETE FROM page WHERE id = {$id}, LIMIT 1";
                                            ^ remove this

答案 1 :(得分:0)

  if ($page == get_page_by_id($id)) {

==进行比较

===比较值和演员

$val = true;
if ($val === true) {
    echo "\$val is bool(true)";
}

if ($val == "true") {
    echo "\$val matches value";
}


if ($val === "true") {
// this will never happen
} else {
echo "\$val doesnt === \"true\"";
}

答案 2 :(得分:0)

  

我不知道错误是什么。

那是因为你没有检查。每次准备或执行查询时,都需要检查错误。如果遇到错误,mysqli中的大多数函数都会返回FALSE

$result = mysqli_query($connection, $query3);
if ($result === false) {
    trigger_error(mysqli_error($connection), E_USER_ERROR);
    header("Location: /error.php");
    exit;
}

未能检查错误情况是数据库程序员犯下的最常见错误之一。

答案 3 :(得分:-1)

尝试在.htaccess中使用php_flag display_errors on 这将允许您查看和识别PHP错误。

相关问题