无法通过 PHP 删除 mysql 条记录
Unable to delete mysql record through PHP
我想通过单击 link 删除 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');
}
?>
替换?使用 & 并删除 URL
中的 "(" ")"
和 ;
<a href="processCategory.php?action=delete?id=(<?php echo $id; ?>);">Delete</a>
你的脚本 processCategory.php 在变量 id 中接收 this = (1) 例如你的 out
echo (int) "(1)";
输出
0
<a>
标签的正确代码应为
<a href="processCategory.php?action=delete&id=<?php echo $id; ?>">Delete</a>
;">删除
删除“()”也许在 php 得到“($id)”
我想通过单击 link 删除 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');
}
?>
替换?使用 & 并删除 URL
中的"(" ")"
和 ;
<a href="processCategory.php?action=delete?id=(<?php echo $id; ?>);">Delete</a>
你的脚本 processCategory.php 在变量 id 中接收 this = (1) 例如你的 out
echo (int) "(1)";
输出
0
<a>
标签的正确代码应为
<a href="processCategory.php?action=delete&id=<?php echo $id; ?>">Delete</a>
;">删除 删除“()”也许在 php 得到“($id)”