我想通过单击链接删除mysql数据库中的记录,但我无法完成它,我无法理解错误。 这是我的代码
HTML
<a href="processCategory.php?action=delete?id=(<?php echo $id; ?>);">Delete</a>
processCategory.php
<?php
require_once '../library/config.php';
require_once '../library/functions.php';
checkUser();
$action = isset($_GET['action']) ? $_GET['action'] : '';
switch ($action) {
case 'add' :
addCategory();
break;
case 'delete' :
deleteCategory();
break;
default :
// if action is not defined or unknown
// move to main category page
header('Location: index.php');
}
function deleteCategory()
{
if (isset($_GET['id']) && (int)$_GET['id'] > 0) {
$id = (int)$_GET['id'];
} else {
header('Location: index.php');
}
// delete the products
$sql = "DELETE FROM tbl_vendors
WHERE id = $id";
dbQuery($sql);
header('Location: ../vendor');
}
?>
答案 0 :(得分:1)
替换?与&amp;并删除网址中的"(" ")"
和;
<a href="processCategory.php?action=delete?id=(<?php echo $id; ?>);">Delete</a>
你的脚本processCategory.php接收变量id this =(1)例如你的
echo (int) "(1)";
输出
0
<a>
标记的正确代码应为
<a href="processCategory.php?action=delete&id=<?php echo $id; ?>">Delete</a>
答案 1 :(得分:0)
“&GT;删除 删除“()”可能在php中获取“($ id)”