php (T_ENCAPSED_AND_WHITESPACE),需要标识符 (T_STRING) 或变量 (T_VARIABLE) 或数字 (T_NUM_STRING)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21431958/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
(T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)
提问by Nithya
I have got Parse error like this:
我有这样的解析错误:
syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)
语法错误,意外的 '' (T_ENCAPSED_AND_WHITESPACE),需要标识符 (T_STRING) 或变量 (T_VARIABLE) 或数字 (T_NUM_STRING)
For below code line
对于下面的代码行
<?php
$query = "SELECT license_parent_type_details.ParentTypeId,license_parent_type_details.TypeName FROM tenant.license_parent_type_details order by TypeName asc";
$result = mysql_query($query);
while($row_list = mysql_fetch_assoc( $result )) {
For below code line
对于下面的代码行
echo '<option value="'.$row_list['ParentTypeId'].'">'<"'.($_POST['seltypes']==$row_list['ParentTypeId'] ? ' selected="selected" : '').'>'. $row_list['TypeName']."'</option>';
回答by ComFreek
Here is the corrected version:
这是更正后的版本:
echo '<option value="', $row_list['ParentTypeId'], '"', ($_POST['seltypes']==$row_list['ParentTypeId'] ? ' selected="selected" ' : ''), '>', $row_list['TypeName'], '</option>';
Mistakes:
错误:
Missing single quote
Superfluous double quote
缺少单引号
多余的双引号
Finding the original position of those errors is left as an exercise for the reader.
找出这些错误的原始位置留给读者作为练习。
回答by ???
Corrected Coded.
更正编码。
echo '<'. ($_POST['seltypes'] == $row_list['ParentTypeId']
? ' selected="selected" '
: '').'>'. $row_list['TypeName'] .'</option>';
- You forgot a
'afterselected="selected" - You had an extra
"after$row_list['TypeName']
- 你忘了
'后selected="selected" - 你有一个额外的
"后$row_list['TypeName']
Visual Aid of above.
以上视觉辅助。
Here's a visual. Look for -->and <--. The one is brackets is the one I removed.
这是一个视觉效果。寻找-->和<--。一个是括号是我删除的那个。
echo '<'. ($_POST['seltypes'] == $row_list['ParentTypeId']
? ' selected="selected" --> ' <--
: '').'>'. $row_list['TypeName'] --> (") <-- .'</option>';

