这个 PHP MySQL 查询有什么问题?
我不断收到以下错误:
您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 1 行 '' 附近使用的正确语法
对于以下查询:
$query = "SELECT `Gift`, `Type`
FROM `gifts`
WHERE `User`= '".mysql_real_escape_string($myuid)."'
LIMIT ".$start.", ".$end;
这是我用来获取 $start 和 $end 变量的代码:
$start = $_GET['start'];
if($start = "") {
$start = 0;
}
$end = $_GET['end'];
if($end = "") {
$end = 7;
}
我发现问题:
我在另一个浏览器中测试了这个脚本,它工作得很好。问题出在 Internet Explorer 9 上。有人知道为什么吗?
I keep getting the following 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 '' at line 1
For the following query:
$query = "SELECT `Gift`, `Type`
FROM `gifts`
WHERE `User`= '".mysql_real_escape_string($myuid)."'
LIMIT ".$start.", ".$end;
Here is the code I use to GET the $start and $end Variables:
$start = $_GET['start'];
if($start = "") {
$start = 0;
}
$end = $_GET['end'];
if($end = "") {
$end = 7;
}
I Found The Problem:
I tested this script in another browser, and it worked just fine. The problem is something with Internet Explorer 9. Anyone know why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
检查
mysql_real_escape_string($myuid)
的返回值。也许它没有返回任何东西。Check the return value of
mysql_real_escape_string($myuid)
. Maybe it is not returning anything.提供的错误应该给你一个线索 -
它说“”附近有一个错误。我将检查 mysql_real_escape_string($myuid) 的值。确保您已转义任何引号“'”并且该值尚未被引用。
the error supplied should give you a clue -
It is saying that there is an error near ''. I would be checking then value of mysql_real_escape_string($myuid). ensure you have escaped any quotes "'" and that the value is already not quoted.
几分钟前我也遇到了同样的问题,而且这个问题也只出现在 Internet Explorer 上。在 Chrome 上,Firefox 工作得很好。
我知道随着数据库中的信息更新,脚本工作正常。
我这边的麻烦是处理后的重定向。
正如我所看到的,IE 不喜欢小写的 url。
通过这样设置
它就可以正常工作。
第一次运行没问题。但随后它刷新并具有 0 值,这就是我们从 SQL 中收到该错误的原因。在我看来,这不是服务器端错误,而是 IE 不想像所有其他浏览器一样读取代码。
I had the exact same trouble few minutes ago and that trouble was only on Internet explorer too. On Chrome, Firefox work just fine.
I know the script works fine as the Info is updated in the Database.
The trouble in my side was the redirection after the process.
<meta http-equiv="refresh" content="0;url=fileX.php" />
And as I can see IE does not like to have url in lower case.
By setting it this way
<meta http-equiv="refresh" content="0;**URL**=fileX.php" />
it works just fine.First time it runs ok. But then it refresh and has 0 valu so that why we are getting that error from SQL. At my eye this is not a server side error but IE that does not want to read the code as all other browser.
你的一些引言都是有角度的;他们需要像这样:'而不是:`
Some of your quotes are all at an angle; they need to be like this: ' not: `
您应该在将查询发送到数据库之前将其打印出来:
更新
OP 在对此答案的注释中提供了 start & 。最终值不会出现在输出中,并且这些值由 GET 请求提供。
输出将使我们更好地了解问题是什么,但我建议使用 sprintf 参数化查询:
You should print the query out before it's sent to the database:
Update
The OP provides in the comments to this answer that the start & end values aren't appearing in the output, and the values are supplied by a GET request.
The output would give us a better idea what the issue is, but I recommend using sprintf to parameterize the query: