当 URL 末尾有撇号时,为什么会出现 SQL 错误?
为什么在 URL 末尾添加 '
时会出现错误?例如:http://mywebsite.com/singel?id=24'
我收到以下错误:
您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 1 行的 '\' LIMIT 1' 附近使用的正确语法
如果我将 '
放置在查询字符串。
出了什么问题,如何修复? 谢谢。
Why do I get an error when I add '
to the end of a URL? For example : http://mywebsite.com/singel?id=24'
I get 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 '\' LIMIT 1' at line 1
This is shown everywhere if I put '
after any id in the query string.
What is wrong, and how it can be fixed?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您正在 SQL 查询中插入非转义变量。如果这个变量恰好包含 SQL 特殊字符,则可能会导致 SQL 语法错误或更糟糕的情况。
在将变量插入 SQL 查询之前,您需要转义它们。
示例:
而不是(这是错误的,不要这样做):
如果
$id
是24'
,查询将变为:可以看到,
24
后面多了一个'
,这是语法错误。You are inserting a non-escaped variable in an SQL query. And if this variable happens to contain SQL special chars, this can cause SQL syntax errors or worse.
You need to escape your variables before inserting them in your SQL queries.
Example:
Instead of (this is WRONG, don't do this):
If
$id
is24'
, the query becomes:As you can see, there is a
'
after24
, which is a syntax error.如果
'
终止了您的查询,则很明显您存在 SQL 注入漏洞。阅读mysql_real_escape_string()
、bobby-tables,并考虑切换到 PDO 准备好的语句。if a
'
kills your query, you very obviously have an sql injection vulnerability. Read up onmysql_real_escape_string()
, bobby-tables, and consider switching to PDO prepared statements.看这里
http://www.codeproject.com/KB/database/SqlInjectionAttacks.aspx
你应该了解一些有关 SQL 注入的知识。您的脚本现在可以注入了
Look here
http://www.codeproject.com/KB/database/SqlInjectionAttacks.aspx
You should learn something about SQL injection. Your Script is injectable now
此错误通常意味着您对 sql 注入持开放态度。这个函数比 mysql_real_escape_string() 稍微复杂一点,因为它还做了 PHP 配置测试,以确保您不会两次转义数据并添加各种 PHP 版本支持! (根据 PHP 手册 1)
只需在每个提交的项目上运行这个漂亮的小函数,用于插入、更新或 where 语句:
例如:
This error usually means you are open to sql injections. This function is a bit more complicated than mysql_real_escape_string(), because it also does a PHP configuration test, to make sure you do not escape the data twice and to add Various PHP version support! (as per PHP Manual 1)
Just run this little nifty function on each of the submitted items, for inserts, updates or where statements:
Ex: