SQL语法错误,请在第1行中检查正确的语法以在'0'附近使用 [英] Error in SQL syntax, check for right syntax to use near '0' at line 1

查看:497
本文介绍了SQL语法错误,请在第1行中检查正确的语法以在'0'附近使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了标题中提到的错误,这是我的PHP文件中的代码,我尝试改革我的查询,但未能纠正错误,有人可以告诉我为什么有这种错误吗,是有我形成错误的方式不正确吗?我已经看到了一些类似的帖子,但是我从那些帖子中知道的问题应该是我的查询,但是我不知道如何更改它.因此,请允许我告诉我查询的问题在哪里,这肯定可以帮助我阐明我的概念.

I have meet the error mentioned in the title, here is the code in my PHP file, I have tried to reform my query, but fail to correct the error, can anyone tell me why there is such kind of error, is there the way I form the error is incorrect? I have seen some similar posts, but what I know from those posts is the problem should be my query, but I have no idea how to change it. So may I ask for your help to tell me where is the problem of my query, this can definitely help me to make clear my concept.

$query = "SELECT * 
    FROM Tech AS T, Client AS C, Site AS S, Log AS L 
    WHERE T.TechID=L.TechID, C.ClientID=L.ClientID, S.SiteID=L.SiteID";
if($sort=="Tech")
   $query += "ORDER BY T.TechName ASC, L.Time DSC";
else if($sort=="Client")
   $query += "ORDER BY C.ClientName ASC, L.Time DSC";
$result = mysql_query($query) or die('Error! ' . mysql_error());; 
print "Real-Time check in/check out<br>";
print "<table><th><td>Tech</td><td>Client</td><td>Site</td>";
print "<td>Date and Time</td><td>Type</td></th>";
while($row = mysql_fetch_array($result)){
print "<tr><td>".$row['T.TechName']."</td>";
print "<td>".$row['C.ClientName']."</td>";
print "<td>".$row['S.SiteName']."</td>";
print "<td>".$row['L.Time']."</td>";
print "<td>".$row['L.Type']."</td></tr>";
}
print "</table>";

下面是错误消息:

错误!您的SQL语法有误;查看与您的MySQL服务器版本相对应的手册以获取正确的语法,以在第1行的"0"附近使用

Error! 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 '0' at line 1

推荐答案

无法看到零从何而来..

Can't see where a zero could be coming from..

但是在将ORDER BY附加到查询的行上,您缺少空格.

But at the lines where you are appending the ORDER BY to your query you're missing a space.

或者在原始$query的末尾添加一个空格,或者在$query +=

Either append a space at the end of you original $query, or append a space to the beginning of your $query +=

对于下降,也应该为DESC而不是DSC

Also for descending it should be DESC not DSC

另外,对于PHP,+ =应该是.=

Also the += should be a .= for PHP

这篇关于SQL语法错误,请在第1行中检查正确的语法以在'0'附近使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆