PHP不喜欢这个T_String. (语法错误意外T_STRING) [英] PHP doesn't like this T_String. (Syntax Error Unexpected T_STRING)
问题描述
我正在编写用于更改用户密码的MYSQL查询.
I was writing a MYSQL query for changing a user's password.
部分代码是:
if ($newpass == $newpass2 && strlen($newpass) < 21 && strlen($newpass) > 5) {
$sqlPasswordQuery = "SELECT value FROM radcheck WHERE attribute = "Cleartext-Password" AND value = "{$oldpass}" AND username = "{$userid}"";
$oldPasswordResult = mysql_query($sqlPasswordQuery);
中间的行是错误的位置(第56行):
The line in the middle is the position of error (Line 56):
Parse error: syntax error, unexpected T_STRING in /(directory)/changepass.php on line 56
使用的表存储了多种属性,仅当行的属性="Cleartext-Password"时,它才是密码行.
The table used stores more than one kind of properties, only when a row's attribute = "Cleartext-Password", it is the password row.
该表由freeradius生成,并用于授权,因此我无法修改其结构.
The table is generated by freeradius, and used for authorisation, so I cannot modify its structure.
我将代码修改为各种样式,例如:
I modified the code to varies kinds of styles, for example this:
$sqlPasswordQuery = SELECT value FROM `radcheck` WHERE `attribute` = "Cleartext-Password" AND `value` = "{$oldpass}" AND `username` = "{$userid}"
但是PHP仍然不喜欢它.
But PHP still doesn't like it.
有人可以帮忙吗?非常感谢.
Could someone give a hand? Thanks a lot.
推荐答案
请求看起来不是这样的:
Shouldn't the request look like that :
$sqlPasswordQuery = "SELECT value FROM radcheck WHERE attribute = 'Cleartext-Password' AND value = '$oldpass' AND username = '$userid'";
?
这是基本的php字符串理解.您不能在已经由双引号分隔的字符串中使用双引号.例如,您必须使用另一个字符串定界符作为简单的引号,或者对它们进行转义(\"
),以便将它们直接解释为字符.
This is basic php string comprehension. You cannot use double quotes in a string that is already delimited by double-quotes. Sou you have to use another string delimiter, as simple quotes, or escape them (\"
), so that they are interpreted directly as a character.
这篇关于PHP不喜欢这个T_String. (语法错误意外T_STRING)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!