Warning: trim() expects parameter 1 to be string, array given in php script

前端 未结 2 1596
生来不讨喜
生来不讨喜 2021-01-16 06:40

i have php script, when i executed this code, i got warning

Warning: trim() expects parameter 1 to be string, array given in home/public_html

相关标签:
2条回答
  • 2021-01-16 07:09

    It appears the error is in your html and not in the php.

    If $_POST['First_Name'] is an array while it should not be, it is likely your html looks something like:

    <input name="First_Name[]" ...>
                           ^^ here, remove this
    
    0 讨论(0)
  • 2021-01-16 07:10

    First of all, your IF statement is all messed up

    if(!isset($_POST['First_Name']) || !isset($_POST['Last_Name']) || 
        {
        died('Sorry, there appears to be a problem.');      
    }
    

    You start it with a bracket, you end it with an OR sign (||). First repair that, to something like this:

    if(!isset($_POST['First_Name']) || !isset($_POST['Last_Name'])){
        died('Sorry, there appears to be a problem.');
    }
    

    Then, if the problem persists type in var_dump($value) and/or var_dump($_POST) inside the antixss() function so it's something like this

    function antixss($value){
        var_dump($value); var_dump($_POST); exit();
        $xss = htmlspecialchars(trim($value));
        return $xss;
    }
    

    And tell us what the output is.

    0 讨论(0)
提交回复
热议问题