$sql=''select Name from users where Username='$username' and
Password='$password'";
回答
您的代碼中有一些雙引號和單引號混淆。在使用它們時始終按照正確的順序匹配它們。
$sql = "select Name from users where Username='$username' and Password='$password' ";
我有最後一個雙引號前加上一個額外的空間,只是爲了澄清在那個地方使用單引號和雙引號的:作爲
您查詢可以得到糾正。
對,但您是否看到[this comment](https:// stackoverflow.com/questions/46758252/parse-error-syntax-error-unexpected-select-t-string#comment80461784_46758252)OP留下了什麼?*「$ sql =''從用戶名中選擇用戶名='$ username'和Password ='$ password'「;我試過這也是「*。 –
@ Fred-ii-該評論中的代碼在語法上是錯誤的,因爲」select「前面的引號是」兩個單引號「,而不是單個雙引號。這就是爲什麼它給用戶提供錯誤。 – shahsani
是的,我現在在編輯器中看到了。他們的評論似乎含有一個開頭的雙引號,在那裏有點難以閱讀。該評論和帖子本身是相同的。 –
- 1. 連接字符串---解析錯誤:語法錯誤,意外T_STRING
- 2. 解析錯誤:語法錯誤,意外'(T_STRING)
- 3. 解析錯誤:語法錯誤,意外的T_STRING與index.php?
- 4. 解析錯誤 - 語法錯誤,意外T_STRING
- 5. PHP解析錯誤:語法錯誤,意外T_STRING
- 6. Drupal 7給解析錯誤:語法錯誤,意外T_STRING
- 7. 解析錯誤:語法錯誤,意外T_STRING
- 8. 解析錯誤:語法錯誤,意外'href'(T_STRING),期待','或';'
- 9. 解析錯誤:語法錯誤,意外T_STRING「」
- 10. PHP PHP解析錯誤:語法錯誤,意外'mysqli_connect'(T_STRING)
- 11. 解析錯誤:語法錯誤,意外的T_STRING,找不到錯誤
- 12. 解析錯誤:語法錯誤,意外'{'
- 13. 解析錯誤:語法錯誤,意外'「
- 14. 解析錯誤:語法錯誤,意外';'
- 15. 解析錯誤:語法錯誤,意外';'
- 16. 解析錯誤:語法錯誤,意外':'
- 17. 解析錯誤:語法錯誤,意想不到的T_STRING
- 18. 解析錯誤:語法錯誤,意想不到的「COMPANY_NAME」(T_STRING)
- 19. Laravel語法錯誤,意外'路線'(T_STRING)
- 20. 語法錯誤,意外 '中'(T_STRING)Laravel 5
- 21. 語法錯誤,意外的T_STRING php
- 22. 解析錯誤:語法錯誤,意外的T_VARIABLE,期待PHP 5.3中的T_STRING
- 23. 解析錯誤:語法錯誤,意外的'相機'(T_STRING),期待','或';'在線205
- 24. PHP newbie error ::解析錯誤:語法錯誤,意外的T_STRING,期待','或';'
- 25. 解析錯誤:語法錯誤,意外'$ class'(T_VARIABLE),期待標識符(T_STRING)
- 26. 解析錯誤:語法錯誤,意外的T_ENCAPSED_AND_WHITESPACE,期待T_STRING或T_VARIABLE或T_NUM_STRING
- 27. PHP的幫助?解析錯誤:語法錯誤,第6行的意外T_STRING
- 28. 解析錯誤:語法錯誤,意外'(T_ENCAPSED_AND_WHITESPACE),預計標識符(T_STRING)或可變
- 29. 解析錯誤:語法錯誤,意想不到的T_STRING ..不能查明錯誤
- 30. T_STRING解析錯誤
刪除語句中的最後一個雙引號 – shahsani
請勿將兩個單引號與雙引號混淆; [瞭解差異](http://php.net/manual/en/language.types.string.php) –
$ sql =''從用戶名中選擇用戶名='$ username'和 Password =' $ password'「;我也試過這個 – Angie