【发布时间】:2012-03-24 14:25:37
【问题描述】:
编辑
感谢到目前为止的帮助。我已经编辑了我的帖子以反映下面建议的更改。我正在使用 PDO 进行数据库连接。我现在的代码如下:
HTML
<a href="includes/delete-customer.php?userID='.$row->customer_id.'">
PHP
<?php
//MySQL Database Connect
include 'includes/config.php';
// confirm that the 'id' variable has been set
if (isset($_GET['userID']) && is_numeric($_GET['userID']))
{
// get the 'id' variable from the URL
$id = $_GET['userID'];
/* Delete row from the customer table */
$id = $dbh->exec("DELETE FROM customer WHERE customer_id = '$id'");
$stmt->execute();
}
?>
config.php
<?php
/*** mysql hostname ***/
$hostname = 'localhost';
/*** mysql username ***/
$username = 'user';
/*** mysql password ***/
$password = 'password';
try {
$dbh = new PDO("mysql:host=$hostname;dbname=testDB", $username, $password);
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>
我很确定 HTML 现在是正确的,问题在于 delete-customer.php 文件。我目前收到以下错误:致命错误:调用非对象上的成员函数 exec()
我不确定如何正确实现 PDO 查询。非常感谢任何进一步的建议。
【问题讨论】:
-
@Morgan 感谢您的回复。我刚刚用我认为可能是问题的内容更新了 html 链接,但它仍然没有从我的数据库中删除记录。非常感谢任何进一步的想法。
-
请检查我在下面发布的答案。为什么要在查询字符串参数中添加文字 $id?