一次又一次地解析错误[关闭]
Posted
技术标签:
【中文标题】一次又一次地解析错误[关闭]【英文标题】:Parse error again and again [closed] 【发布时间】:2013-04-27 14:49:39 【问题描述】:这个主题已经发布了好几次,但是在 SO 中发布的解决方案似乎没有帮助。我检查了分号、空格和查询,但每当我调用 subjaccess.php 时,我仍然会收到 php 上的解析错误。
Parse error: syntax error, unexpected T_STRING in /home/a8367888/public_html/subjacces-s-request.php on line 14
这是我的 php 代码:
<?php
$mysql_hostname = "localhost";
$mysql_database = "database";
$mysql_user = "username";
$mysql_password = "password";
//$pass = $_POST['email'];
$pass = "blahblach@gmail.com";
$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password)
or die("Opps something went wrong");
mysql_select_db($mysql_database, $bd) or die("Oops something went wrong");
$query = "SELECT (a.acode) as "access_id", (s.s_first_name) as "fname", (s.s_middle_initial) as "mname", (s.s_last_name) as "lname", (a.s_email) as "email", (a.req_subj) as "subjcode"
FROM access a, student s
WHERE a.s_email = s.s_email
AND a.t_email = '$pass'
AND a.access_status = "pending";
$result = mysql_query($query) or die('MySql Error' . mysql_error());
while ($row = mysql_fetch_array($result))
$res[]=array('aid'=> $row['access_id'],'fname'=> $row['fname'],'mname'=> $row['mname'], 'lname'=> $row['lname'], 'email'=> $row['email'], 'subj'=> $row['subjcode']);
echo '$res';
$response['request'] = $res;
print(json_encode($response));
?>
希望得到您的回应。
【问题讨论】:
检查报价。你这个骗子,你说你检查了查询。 见鬼,甚至 SO 语法高亮显示错误! 这是你的真实密码吗? 请学习语法basics ... 【参考方案1】:您的字符串中有双引号,尽管它被"
包围。这会破坏您的 PHP 代码。但无论如何你都不需要它们。此外,您应该使用JOIN
而不是FROM a, b
。并且查询中的所有标识符都应该用 backtics ` 引用。最终查询应如下所示:
$query = "
SELECT
`a`.`acode` AS `access_id`,
`s`.`s_first_name` AS `fname`,
`s`.`s_middle_initial` AS `mname`,
`s`.`s_last_name` AS `lname`,
`a`.`s_email` AS `email`,
`a`.`req_subj` AS `subjcode`
FROM `access` `a`
JOIN `students` `s`
ON `a`.`s_email` = `s.s_email`
AND `a`.`t_email` = '$pass'
AND `a`.`access_status` = 'pending'
";
【讨论】:
【参考方案2】:改一下
$query = "SELECT (a.acode) as "access_id", (s.s_first_name) as "fname", (s.s_middle_initial) as "mname", (s.s_last_name) as "lname", (a.s_email) as "email", (a.req_subj) as "subjcode"
到
$query = "SELECT (a.acode) as 'access_id', (s.s_first_name) as 'fname', (s.s_middle_initial) as 'mname', (s.s_last_name) as 'lname', (a.s_email) as 'email', (a.req_subj) as 'subjcode'
【讨论】:
【参考方案3】:试试这个
$query = "SELECT (a.acode) as " . access_id . ", (s.s_first_name) as " . fname . ", (s.s_middle_initial) as " . mname . ", (s.s_last_name) as " . lname . ", (a.s_email) as "email", (a.req_subj) as " . subjcode
【讨论】:
以上是关于一次又一次地解析错误[关闭]的主要内容,如果未能解决你的问题,请参考以下文章
如何避免要求用户一次又一次地登录(连接)到我的 Facebook 应用程序?