2016-12-11 1 views
0

저는 현재 프로젝트의 백 엔드에있는 전자 상거래 프로젝트에서 작업하고 있습니다.이 프로젝트에서 카테고리의 메뉴 또는 하위 메뉴를 추가하거나 제거 할 수 있습니다. 내가 코드를 여기에 undefined function to sanitize()

Fatal error: Call to undefined function sanitize() in C:\xampp\htdocs\project\admin\categories.php on line 15

를 오류입니다 얻고있어 그

내가 체크 한 DLL을

을 사용할 수 있습니다

<?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'); 
} 
} 


?> 
+3

오류는 꽤 직접적인 것처럼 보입니다. 'sanitize' 함수가 정의되지 않았습니다. SQL 주입이나 XSS 주입을 방지하기위한 계획입니까? SQL이라면 제거하고 매개 변수화 된 쿼리를 사용하십시오. – chris85

답변

0

sanitize가 정의되어 있지, 나에게 보인다 범위에 있습니다. 표준 함수가 아니므로 코드 내의 어딘가에 있어야합니다. 당신은 대부분이 같은 mysqli_real_escape_string와 직접 대체 할 수 있습니다 :

$parent = mysqli_real_escape_string($_POST['parent']); 
$category = mysqli_real_escape_string($_POST['category']); 

You should use PDO instead, that would be much better!

희망이 도움이!

+0

이전 기능에 대한 사용법을 알 수없는 경우 함수 교환을 권하지 않습니다. mysqli_real_escape_string에는 연결 문자열이 필요하다. 왜'PDO'가'mysqli'보다 훨씬 좋은가? 둘 다 매개 변수화 된 쿼리를 지원합니다. – chris85