Php 使用“修剪”功能时无法编辑

Php 使用“修剪”功能时无法编辑,php,html,Php,Html,我正在设计一个应用程序,在我的模式中遇到了一个奇怪的错误,我无法编辑条目 以下是显示错误所在的模式: <?php include_once dirname(dirname(dirname(__FILE__))) . "/const.php"; include_once PHP_PATH . "/config1.php"; include_once CONFIG_PATH.'/modal/routemgmt/route_mgmt.php'; function

我正在设计一个应用程序,在我的模式中遇到了一个奇怪的错误,我无法编辑条目

以下是显示错误所在的模式:

 <?php
    include_once dirname(dirname(dirname(__FILE__))) . "/const.php";
    include_once PHP_PATH . "/config1.php";
    include_once CONFIG_PATH.'/modal/routemgmt/route_mgmt.php';

   function sanitize($input) {
   if (is_array($input))
        return array_map('sanitize', $input);
    else
        return htmlspecialchars(trim($input));
}

    // Sanitize all the incoming data
    $sanitized = array_map('sanitize', $_POST);
    $reason = $sanitized['reason'];

    if($reason == "insert"){
        $staffs = [];
        $stops = [];
        $name = $sanitized['rname'];
        $code = $sanitized['rcode'];
        $desc = $sanitized['rdesc'];
        $vnum = $sanitized['vnum'];
        $stf = $_POST['staff'];
        $st = isset($_POST['stops'])? $_POST['stops']: [];
        $st = [];
    //    foreach($staffs as $staff){
    //        $stf[] = array_map('sanitize', $staff);
    //    }
    //    if(isset($stops)){
    //        foreach($stops as $stop){
    //            $st[] = array_map('sanitize', $stop);
    //        }
    //    }

        $val = insertRoute($conn,$name, $code, $desc, $vnum, $stf, $stops);
        echo $val;
    }

    if($reason == "view"){
        $id = $sanitized['id'];
        $val = [];

        $val = viewRoute($conn,$id);
        echo json_encode($val);
    }

    if($reason == "edit"){
        $stf = [];
        $stp = [];
        $id = $sanitized['pkid'];
        $name = $sanitized['rname'];
        $code = $sanitized['rcode'];
        $desc = $sanitized['rdesc'];
        $vnum = $sanitized['vnum'];
        $estaffs = $_POST['estaff'];
        $estops = $_POST['estops'];
        $edel = $_POST['del'];

        foreach($estaffs as $val){
            $stf[] = array_map('sanitize', $val);
        }
        foreach($estops as $val){
            $stp[] = array_map('sanitize', $val);
        }
        $cnt = 0;$n_stp = [];
        for($i = 0; $i<sizeof($stp); $i++){
            if($stp[$i]['stat'] != "Exist"){
                $n_stp[$cnt] = $stp[$i];
                $cnt++;
            }
        }

        $val = editValues($conn,$id, $name, $code, $desc, $vnum, $stf, $n_stp, $edel);
        echo $val;
    }

    if($reason == "delRoute"){
        $id = $sanitized['id'];
        $val = delRoute($conn,$id);
        echo $val;
    }

I tried changing the function to :

    function sanitize($input) {
        return htmlspecialchars(trim($input));
    }

在这个函数中,您在if语句中返回数组,而数组始终应该是字符串

替换:

   function sanitize($input) {
   if (is_array($input))
        return array_map('sanitize', $input);
    else
        return htmlspecialchars(trim($input));
}
   function sanitize($input) {
   if (is_array($input))
        return sanitize($input);
    else
        return htmlspecialchars(trim($input));
   }
array_map('sanitize', $val);
sanitize($val);
与:

   function sanitize($input) {
   if (is_array($input))
        return array_map('sanitize', $input);
    else
        return htmlspecialchars(trim($input));
}
   function sanitize($input) {
   if (is_array($input))
        return sanitize($input);
    else
        return htmlspecialchars(trim($input));
   }
array_map('sanitize', $val);
sanitize($val);
您需要以字符串而不是数组的形式返回值。不要弄乱
$\u POST
一个

全部替换:

   function sanitize($input) {
   if (is_array($input))
        return array_map('sanitize', $input);
    else
        return htmlspecialchars(trim($input));
}
   function sanitize($input) {
   if (is_array($input))
        return sanitize($input);
    else
        return htmlspecialchars(trim($input));
   }
array_map('sanitize', $val);
sanitize($val);
与:

   function sanitize($input) {
   if (is_array($input))
        return array_map('sanitize', $input);
    else
        return htmlspecialchars(trim($input));
}
   function sanitize($input) {
   if (is_array($input))
        return sanitize($input);
    else
        return htmlspecialchars(trim($input));
   }
array_map('sanitize', $val);
sanitize($val);

你的
$\u帖子['estaff']在哪里
$\u POST['estops']值。错误是因为您发送的是数组而不是字符串值。据我所知,它在trim中传递的是数组而不是字符串。不,是你传递了一个数组来修剪。这不是代码自己做的。错误是由您对sanitize函数的更改引起的,请将其放回原处,那么原始问题是什么?和的可能重复:
$sanitized=array\u map('sanitize',$\u POST)
和POST绝对是一个数组。
返回sanitize($input)?对吗?将只将相同的数组传递给该行所在的函数是的。,,,,,