无法通过PHP删除mysql记录
我想通过点击链接删除mysql数据库中的记录,但我无法完成,我无法理解错误。 这是我的密码 HTML无法通过PHP删除mysql记录,php,html,mysql,delete-row,Php,Html,Mysql,Delete Row,我想通过点击链接删除mysql数据库中的记录,但我无法完成,我无法理解错误。 这是我的密码 HTML processCategory.php <?php require_once '../library/config.php'; require_once '../library/functions.php'; checkUser(); $action = isset($_GET['action']) ? $_GET['action'] : '
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>
输出
0
;“>删除
删除“()”可能在php中得到“($id)”错误在哪里。甚至是不安全的!不应该是这样的:$sql=“从tbl_供应商那里删除id=”。$id;
?你在说什么错误?@Jay Blanchard但他正在将id字段更改为int-sono-injection你的链接中的id周围似乎有括号id=()
这将计算为id=(1)
所以请尝试id=
也只需在dbQuery()中添加exit('hello');为了确保您的deleteCegory()函数可以访问dbQuery(),您可能希望通过发布正确的代码而不是错误的代码来让答案更清楚。。。
echo (int) "(1)";
0
<a href="processCategory.php?action=delete&id=<?php echo $id; ?>">Delete</a>