Does anyone know the meaning behind this php error message?

后端 未结 6 1954
别跟我提以往
别跟我提以往 2021-01-22 20:47

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING is the message. It came up from this line of code:

<         


        
6条回答
  •  北恋
    北恋 (楼主)
    2021-01-22 21:33

    For interpolation of one-dimensional array values into strings, use this syntax:

    "foo = $_POST[bar]"
    

    Notice no quotes.

    For interpolating nested arrays or generally using the normal syntax, use braces:

    "foo = {$_POST['bar']}"
    

    In no case though do any of this with SQL queries, you need to escape values before plugging them into queries. So, do this:

    $query = sprintf('SELECT foo FROM bar WHERE baz = "%s"',
                     mysql_real_escape_string($_POST['baz']));
    

提交回复
热议问题