SQL查询中有关引号的错误

时间:2016-07-15 11:24:08

标签: php mysql database phpmyadmin mysql-error-1064

我在php中运行以下查询:

$link = $_GET['link'];
$query = "SELECT DISTINCT sub_category FROM phonebook ORDER BY sub_category WHERE category = '$link' "; 
echo $query;
$sql = mysql_query($query) or die(mysql_error());

它给出了以下错误:

  

SELECT DISTINCT sub_category FROM phonebook ORDER BY sub_category WHERE category =' Administration'您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册,以获得正确的语法,以便在' WHERE category =' Administration'''在第1行

我无法理解引号中的错误是什么?

3 个答案:

答案 0 :(得分:4)

尝试以下方法:

$query = "SELECT DISTINCT sub_category FROM phonebook ORDER BY sub_category WHERE category = '$link' ";

进入

$query = "SELECT DISTINCT sub_category FROM phonebook WHERE category = '".$link."' ORDER BY sub_category ";

你犯了错误" sub_caregory":

$query = "SELECT DISTINCT sub_caregory FROM phonebook WHERE category = '".$link."' ORDER BY sub_caregory ";

答案 1 :(得分:0)

ORDER BY应该在关闭之后 你做不到

SELECT 
FROM 
OREDER BY
WHERE 

ORDER IS

SELECT 
FROM 
WHERE 
GROUP BY 
HAVING 
ORDER BY 

答案 2 :(得分:0)

尝试以下查询: $ query =" SELECT DISTINCT sub_category FROM phonebook WHERE category ='"。$ link。"' ORDER BY sub_category&#34 ;; 要查看完整的select语句,您可以在此处查看http://dev.mysql.com/doc/refman/5.7/en/select.html