unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING error

后端 未结 6 1847
臣服心动
臣服心动 2020-11-30 06:45

i\'ve been staringly blanky at this error and can\'t seem to know what the problem is.When i run the query i get this error:

unexpected T_ENCAPSED_AND

相关标签:
6条回答
  • 2020-11-30 07:06

    My issue was also within the heredoc. I had it within an if/then statement and the closing bracket directly after the semicolon. So I moved the closing bracket to its own line and issue was fixed.

    I changed:

    ... ;}
    

    to:

    ... ;
    }
    
    0 讨论(0)
  • 2020-11-30 07:11

    Change your code to.

    <?php
    $sqlupdate1 = "UPDATE table SET commodity_quantity=".$qty."WHERE user=".$rows['user'];
    ?>
    

    There was syntax error in your query.

    0 讨论(0)
  • 2020-11-30 07:14

    Try

    $sqlupdate1 = "UPDATE table SET commodity_quantity=$qty WHERE user={$rows['user']} ";
    

    You need curly brackets for array access in double quoted strings.

    0 讨论(0)
  • 2020-11-30 07:21

    Use { before $ sign. And also add addslashes function to escape special characters.

    $sqlupdate1 = "UPDATE table SET commodity_quantity=".$qty."WHERE user=".addslashes($rows['user'])."'";
    
    0 讨论(0)
  • 2020-11-30 07:22

    In my case, heredoc caused the issue. There is no problem with PHP version 7.3 up. Howerver, it error with PHP 7.0.33 if you use heredoc with space.

    My example code

    $rexpenditure = <<<Expenditure
                      <tr>
                          <td>$row->payment_referencenumber</td>
                          <td>$row->payment_requestdate</td>
                          <td>$row->payment_description</td>
                          <td>$row->payment_fundingsource</td>
                          <td>$row->payment_agencyulo</td>
                          <td>$row->payment_agencyproject</td>
                          <td>$$row->payment_disbustment</td>
                          <td>$row->payment_payeename</td>
                          <td>$row->payment_processpayment</td>
                      </tr>
    Expenditure;
    

    It will error if there is a space on PHP 7.0.33.

    0 讨论(0)
  • 2020-11-30 07:28

    try this

    echo $sqlupdate1 = "UPDATE table SET commodity_quantity=$qty WHERE user='".$rows['user']."' ";
    
    0 讨论(0)
提交回复
热议问题