2016-04-24 135 views
0

我想从我的表中删除一些行。但是,当我点击删除,这只是给我一个空白页面。我很确定id值和我的db连接。无法从数据库中删除行

这是我的代码:

// connect to the database 
include('connect-db.php'); 

// confirm that the 'id' variable has been set 
if (isset($_GET['id']) && is_numeric($_GET['id'])) { 
    // get the 'id' variable from the URL 
    $id = $_GET['id']; 

    // delete record from database 
    if ($stmt = $mysqli->prepare("DELETE FROM my_table WHERE id = ? LIMIT 1")) { 
     $stmt->bind_param("i",$id); 
     $stmt->execute(); 
     $stmt->close(); 
    } else { 
     echo "ERROR: could not prepare SQL statement."; 
    } 
    $mysqli->close(); 

    // redirect user after delete is successful 
    header("Location: Dashboard.php"); 
} else { 
    // if the 'id' variable isn't set, redirect the user 
    header("Location: Dashboard.php"); 
} 
+0

你能[打开错误报告](http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php),看看你得到什么错误? – Chris

回答

0

还有一个类似的问题MySQLi Prepared Statement not executing 。基本上,你可以尝试直接在数据库中运行SQL来查看是否有任何错误。同时确认数据库用户具有删除权限,并且该ID在数据库中以整数存储。

+0

我测试了phpmyadmin中的mysqli查询和代码工作,但仍然当我点击.../delete.php?id =?链接它没有任何回报,并goiing空白 –

-1

首先我建议你使用$ _ POST方法,你可以阅读更多关于它GET vs. POST。我相信其他的东西需要为bindParam()声明我忘记了(我也是PHP新手)。我不知道如何使用bindParam()函数。

+0

mysqli没有'bind_value()'方法。 – Chris