Home > Database > Mysql Tutorial > Why Am I Getting \'unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING\'?

Why Am I Getting \'unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING\'?

Patricia Arquette
Release: 2024-10-26 14:31:30
Original
856 people have browsed it

Why Am I Getting

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'] ";
Copy after login

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']."' ";
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template