Welcome to WebmasterWorld Guest from 34.204.203.142

Forum Moderators: phranque

Message Too Old, No Replies

submitting the same data to a database multiple times

     
9:30 pm on Mar 29, 2005 (gmt 0)

New User

10+ Year Member

joined:Mar 18, 2005
posts:11
votes: 0


good day everyone!

i have probably a rather peculiar question...usually what i wish to do is the opposite of what most web designers want (lol!), BUT what i wish to do is when a user enters in data in a form and submits it (only once), that data gets posted to the database +times based on the number they enter in the "how many did you purchase?" field. in other words, this field will determine HOW MANY times that data is re-submitted to the database. for example...if the user enters in they bought 3 items, then the data they submit (by only hitting the submit button once) will be entered into the database table tblRegistration 3 times, with a unique id for each entry.

the reasoning behind this is this is for a contest, so the user could be entered in the contest +times based on the number of items they purchased.

i have a submit.asp page that grabs that data from my form.asp page and submits to my database...this is the code in my submit.asp i tried hoping it would do what i wanted but to no avail (it submits the data but only once):

i = Request.Form("number")
Do while i > 0
sSQL = "INSERT into tblRegistration(DateSubmitted, FirstName, LastName, CompanyName, AmountOnOrder, OrderNumber) values ('" & dateSubmitted & "', '" & firstName & "', '" & lastName & "', '" & companyName & "', '" & numberOnOrder & "', '" & orderNumber & "')"
i = i - 1
Loop

All advice welcomed! Thank you kindly!

Kind regards,
Harlequin

9:35 pm on Mar 29, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member txbakers is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Sept 1, 2001
posts:4392
votes: 0


Your looping idea is correct, however, you need to EXECUTE the query that many times, not just write the SQL statement.

Put the Execute statement in your loop and you'll be fine.

9:54 pm on Mar 29, 2005 (gmt 0)

New User

10+ Year Member

joined:Mar 18, 2005
posts:11
votes: 0


hello txbakers!

thank you for your quick response! i will definitely give your advice a try! thank you!

kind regards,
harlequin

12:38 am on Mar 30, 2005 (gmt 0)

Full Member

10+ Year Member

joined:Feb 19, 2004
posts:207
votes: 0


Seems like a lot of redundant data to me. What kind of database are you using? If your database keeps a transaction log it could quickly grow pretty large.
5:26 am on Mar 30, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:Feb 20, 2004
posts:139
votes: 0


You took a wrong approach. Do not duplicate the info in the database and record the number as it was enter. When you will want to select the winner you should just count all submissions and pick up a (random) number in the range 0..#submissions then count until you'll find that (Nth) submission.
2:47 pm on Mar 30, 2005 (gmt 0)

New User

10+ Year Member

joined:Mar 18, 2005
posts:11
votes: 0


txbakers...

that worked perfectly! thank you! :D

raywood...

i'm using an access database.

and yes, i do agree it is redundant, but the contest is more for our dealers so there won't be an enormous amount of entries. but i will definitely consider all of your advice. ;)

i greatly appreciate all of your time and input! thank you! :D

kind regards,
harlequin