Home > Back-end >  Need Classic ASP for dynamic declaration of request inputs to add database record
Need Classic ASP for dynamic declaration of request inputs to add database record

Time:07-18

This is for Classic ASP

I have a webform that submits 64 form inputs for 64 columns - not rows] and that number can increase depending on the number of players. I usually define those variables while filtering their input by using code like:

strData1 = cleanName(request("Data1"))
strData2 = cleanName(request("Data2"))
strData3 = cleanName(request("Data3"))

Then write to SQLExpress like:

SQL = "Insert Into Scores ( [Data1], [Data2], [Data3] ) " & _
"Values ( '" & strData1 & "', '" & strData2 & "', '" & strData3 & "' )"
dbConnection.Execute(SQL)

But with 64 columns that can vary in quantity, a function that dynamically reads all request fields, declares them while filtering them, and then dynamically populates the write/update statement would be 100 times better.

Is this even possible?

CodePudding user response:

The answer to "is this even possible?" is NO!

There is no alternative language or method that could possibly work to cater for 64 columns of varying number and especially not one that can increase the number of columns in this case. While it may be possible to dynamically write a varying number of request inputs by using a loop, retrieving those values in a form that could edit and re-submit would be a horrendous task and no saving on the time/effort that it would take to create a hard-coded routine for each and every request input.

The best solution is the alternative suggested by Charlieface, which is to break the task down by creating a table for "Matches" and a separate table for "Games" that includes a column for [MatchID] which is the primary key used in the Matches table.

Then the number of players and games played can be limitless and without complex scripting to write and retrieve the data.

  • Related