此主题已经多次发布,但此处发布的解决方案似乎没有帮助。我已经检查了分号,空格和查询,但每当我调用subjaccess.php时,我仍然在php上收到解析错误。
Parse error: syntax error, unexpected T_STRING in /home/a8367888/public_html/subjaccessrequest.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));
?>
希望得到你的答复。
答案 0 :(得分: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'
答案 1 :(得分: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 :(得分:0)
试试这个
$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