Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

On my first page I have an array defined as:

dim selection
    selection = Array("name", "city")

On the following ASP page I'm trying to call to those same variables for an SQL query:

dim selection
    selection = array(request.form("name"), request.form("city"))

In my SQL query:

sqlstr = "SELECT * from Users where name='" + selection(0) + "' and city= '" + selection(1) + "'

This doesn't work, and I've tried tooling around with it but I can't seem to find a working solution. What am I missing?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
130 views
Welcome To Ask or Share your Answers For Others

1 Answer

Html forms don't do arrays. The best you're gonna get via Request.Form() is a comma-delimited list, and that's if you have multiple form fields with the same name: there is just no way to pass along an entire array "in one piece".

Based on your "I've forced 2 SQL columns into the same select box" comment, I think what you need is something like:

<select name='Person' size='1'>
    <option value='NameID1~AddressID1'>John Smith, 123 Main Street</option>
    <option value='NameID1~AddressID2'>John Smith, 345 Elm Avenue</option>
    ...
</select>

... which you would handle on the submit end by splitting on the delimiter character:

const delimiter = "~"
selection = Request.Form("Person")
If Instr(selection,delimiter) > 0 Then selection = Split(selection,delimiter)

Naturally, you need to choose your delimiter character(s) such that there's no chance it'll occur in your option values.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...