您的 SQL 语法有误;检查与您的MySQL服务器版本相对应的手册,了解在第1行的“”附近使用的正确语法


You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

我在 MYSQL 中遇到错误

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

有人可以向我解释这个错误是怎么回事吗?谢谢。

PHP代码:

<?php
$link = connectToDB();
 $strXML = "<chart caption='Factory Output report' subCaption='By Quantity' pieSliceDepth='30' showBorder='1' formatNumberScale='0' numberSuffix=' Units'>";


    $result = mysqli_query($link, "SELECT DISTINCT PROFILE FROM tbljocreator GROUP BY PROFILE");
    $show = mysqli_fetch_array($result);
    if($result) {
    while ($ors = mysqli_fetch_array($result)) {
    $strQuery = "select PROFILE, sum(MT) as totalLM from tbljocreator where PROFILE =" .$ors['PROFILE'];
    $result2 = mysqli_query($link, $strQuery) or die(mysqli_error($link));
    $getresult2 = mysqli_fetch_array($result2); 

    $strXML .= "<set label='" . $ors['profile'] . "' value ='" . $getresult2['totalLM'] . "' />";

    mysqli_free_result($result2);
    }
    }
    mysqli_close($link);
    $strXML .= "</chart>";
        echo renderChart("FusionCharts/Column3D.swf", "", $strXML, "JoCreator", 450, 300, false, true);
    ?>

请为我解释清楚。

听起来$ors['PROFILE']是一个空变量。 在某处执行print_r($ors),并将查询更改为$strQuery = "select PROFILE, sum(MT) as totalLM from tbljocreator where PROFILE = '" .$ors['PROFILE']."'";,以便下次不会引发该错误。

顺便说一下,作为解释,错误是因为如果变量为空,查询将在=后结束。 由于它在此处需要一个参数,因此它会抛出错误。 由于错误仅显示问题的开头,即查询的最后,因此它是一个空字符串。(靠近")