Home >Database >Mysql Tutorial >Why Am I Getting \'unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING\'?
Unexpected T_ENCAPSED_AND_WHITESPACE, Expecting T_STRING: Resolving the Error
When attempting to execute an SQL query, you may encounter the error message "unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING." This error typically pertains to a syntax issue in the query string.
Cause:
The error usually occurs when whitespace (spaces or tabs) is present within a quoted string in the query. PHP interprets whitespace characters as part of the string when it should be a separate entity.
Solution:
To resolve this error, ensure that no unnecessary whitespace is present within the quoted strings in your query. In this specific case, it appears that the error occurs in the following line:
$sqlupdate1 = "UPDATE table SET commodity_quantity=$qty WHERE user=$rows['user'] ";
Notice the whitespace character at the end of the string before the semicolon.
The solution is to remove the whitespace character and wrap the user variable in quotes, as seen in the suggested answer:
$sqlupdate1 = "UPDATE table SET commodity_quantity=$qty WHERE user='".$rows['user']."' ";
The above is the detailed content of Why Am I Getting \'unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING\'?. For more information, please follow other related articles on the PHP Chinese website!