0

I am trying to use an ASP variable to determine how the sql is ordered.

ASP SQL ERROR LINE:

Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC Text Driver] Syntax error (missing operator) in query expression '& supplier_name &'.

/junk/airsearch/search.htm, line 106

Relevant line:

conDB = "SELECT * FROM mul.csv WHERE ucase(supplier_name) LIKE ucase('%"+src_supplier_name+"%') AND ucase(aircraft_type) LIKE ucase('%"+src_aircraft_type+"%') ORDER BY & src_order & "   

ASP CODE:

<%
        Dim connectString, connect, conDB, sconDB, lDB, con, scon, lcon, src_ccn, src_state, src_order
        connectString = "Driver={Microsoft Text Driver (*.txt; *.csv)}; DBQ=" & Server.MapPath("data")
              src_supplier_name = Request.QueryString("supplier_name")
              src_aircraft_type = Request.QueryString("aircraft_type")
              src_state = Request.QueryString("state")


            src_order = "supplier_name"


        set connect = Server.CreateObject("ADODB.connection")
        connect.open connectString

        if src_state = "" then
            conDB = "SELECT * FROM mul.csv WHERE ucase(supplier_name) LIKE ucase('%"+src_supplier_name+"%') AND ucase(aircraft_type) LIKE ucase('%"+src_aircraft_type+"%') "   
            lDB = "SELECT * FROM mul.csv WHERE ucase(supplier_name) LIKE ucase('%"+src_supplier_name+"%')" 
        elseif src_state = "any" then
            conDB = "SELECT * FROM mul.csv WHERE ucase(supplier_name) LIKE ucase('%"+src_supplier_name+"%') AND ucase(aircraft_type) LIKE ucase('%"+src_aircraft_type+"%') ORDER BY & src_order & "   
            lDB = "SELECT * FROM mul.csv WHERE ucase(supplier_name) LIKE ucase('%"+src_supplier_name+"%') AND ucase(aircraft_type) LIKE ucase('%"+src_aircraft_type+"%') ORDER BY & src_order & " 
        else 
            conDB = " SELECT * FROM mul.csv WHERE ucase(state) LIKE ucase('%"+src_state+"%') AND ucase(supplier_name) LIKE ucase('%"+src_supplier_name+"%') AND ucase(aircraft_type) LIKE ucase('%"+src_aircraft_type+"%')"
            lDB = " SELECT * FROM mul.csv WHERE ucase(state) LIKE ucase('%"+src_state+"%') AND ucase(supplier_name) LIKE ucase('%"+src_supplier_name+"%') AND ucase(aircraft_type) LIKE ucase('%"+src_aircraft_type+"%')"
        end if

        sconDB = "SELECT * FROM mul.csv"    

        set con = connect.execute(conDB)
        set scon = connect.execute(sconDB)
        set lcon = connect.execute(lDB)
%>
1
  • 1
    What you are doing with the src_state, src_supplier_name, and src_aircraft_type makes your code vulnerable to Sql Injection attacks. You're practically begging to get hacked. Commented Jan 31, 2013 at 4:22

1 Answer 1

1

try to modify like this:

conDB = "SELECT * FROM mul.csv WHERE ucase(supplier_name) LIKE ucase('%" & src_supplier_name & "%') AND ucase(aircraft_type) LIKE ucase('%" & src_aircraft_type & "%') ORDER BY " & src_order   
Sign up to request clarification or add additional context in comments.

3 Comments

Isn't there suppose to be an ending " for the entire sql statement?
@sephiith Sql doesn't care about that. There is supposed to be a " ending in for string literals in your vb code. %') ORDER BY is a string literal. src_order is not.
SQL Injection is worth mentioning in this context.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.