【问题标题】:ASP Classic SQL Query does not work as intendedASP 经典 SQL 查询无法按预期工作
【发布时间】:2015-03-29 16:14:23
【问题描述】:

我在 HTML 中使用 ASP 来创建网站。 在我的一个页面上,SQL 查询sqlString = "SELECT * FROM Property_Details WHERE " &_ " Price BETWEEN '" & minPrice & "' AND '" & maxPrice & "' " &_ "OR Address_2 LIKE '" & searchFor & "' " 用于搜索数据库并根据表单上的内容显示正确的条目。这适用于查询的Address_2 部分,但BETWEEN 无法正常工作。 minPricemaxPrice 都已提前声明,并且正在获取正确的表单数据,因为我已经使用 <%= minPrice %> 对其进行了测试,我错过了什么?

【问题讨论】:

    标签: sql asp-classic


    【解决方案1】:

    我认为您的 minPricemaxPrice 是数字,因此您不需要撇号。目前,通过您的查询,您得到的 SQL 类似于:

    SELECT * FROM Property_Details 
    WHERE Price BETWEEN '10' AND '20'
    

    因为 10 和 20 是数字,所以你不应该在它们周围使用'。尝试将您的查询更改为以下内容:

    sqlString = "SELECT * FROM Property_Details WHERE " &_
    " Price BETWEEN " & minPrice & " AND " & maxPrice & " " &_
    "OR Address_2 LIKE '" & searchFor & "'  "
    

    顺便说一句 - 我不知道 minPricemaxPricesearchFor 来自哪里,但如果它们来自用户输入,您可能会受到 SQL injection attacks 的攻击

    【讨论】:

    • 谢谢,它们是用searchFor = Replace( Request.Form( "searchFor" ), "'", "''") maxPrice = Replace( Request.Form( "maxPrice" ), "'", "''") minPrice = Replace( Request.Form( "minPrice" ), "'", "''") 快速问题声明的,如果数据库条目是长整数,我需要用 CLng() 转换它们吗?
    • 您需要在查询中将原始数字传递给minPricemaxPrice,因此请尝试将传入的值转换为数字。而且您似乎很容易受到 SQL 注入攻击,网上有多个来源介绍了如何解决这个问题
    • 替换功能是我的尝试,我首先用' or ''=' 闯入了我的网站,然后用这个功能阻止了它
    • 你有我如何将原始数字传递给minPriceMaxPrice 的示例吗?我尝试使用maxPrice = CLng( maxprice ) 转换它们,但这不起作用
    猜你喜欢
    • 2010-10-04
    • 1970-01-01
    • 1970-01-01
    • 2019-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多