我正在开发一个电子商务项目,该项目目前位于该项目的后端,您可以在该项目中添加或删除类别的菜单或子菜单。
我已检查dll已启用
这是我得到的错误
致命错误:在第15行的C:\ xampp \ htdocs \ project \ admin \ categories.php中调用未定义的函数sanitize()
这是代码
<?php
require_once $_SERVER['DOCUMENT_ROOT'].'/project/core/init.php';
include 'includes/head.php';
include 'includes/navigation.php';
$sql = "SELECT * FROM categories WHERE parent = 0";
$result = $db->query($sql);
$errors = array();
// when the form is cick process
$Category = '';
$parent= '';
if(isset($_POST) && !empty($_POST)){
$parent = sanitize($_POST['parent']);
$category = sanitize($_POST['category']);
$sqlform = "SELECT * FROM categories WHERE category ='$category' AND parent = '$parent'";
$fresult = $db->query($sqlform);
$count = mysqli_num_rows($fresult);
//if category is blank
if($category == ''){
$errors[] .= 'The category cannot be left blank';
}
//if it already exixt in database
if($count > 0){
$errors[] .= $category.' Already exits please choose a new category';
}
//display error or update database
if(!empty($errors)){
$display = display_errors($errors);?>
<script>
jQuery('document').ready(function(){
jQuery ('#errors').html('<?php $display;?>');
});
</script>
<?php } else{
//update database
$updatesql = "INSERT INTO categories(category,parent)VALUES ('$category','$parent')";
$db->query($updatesql);
header('location:categories.php');
}
}
?>
答案 0 :(得分:0)
在我看来,$parent = mysqli_real_escape_string($_POST['parent']);
$category = mysqli_real_escape_string($_POST['category']);
并未在范围内定义。它不是标准函数,因此它应该在代码中的某个位置。您最有可能直接用mysqli_real_escape_string
代替它:
hash -r
which linter
您应该使用PDO代替,这会更好!
希望这有帮助!