Adding Multiple Records via Checkboxes

Results 1 to 3 of 3

Thread: Adding Multiple Records via Checkboxes

  1. #1
    Linda N. Guest

    Default Adding Multiple Records via Checkboxes

    I was wondering if someone would be able to help me troubleshoot this code (or at least point me in the right direction). I have a search results page(form) which lists records with checkboxes (all the same name="LeadID" and different number values based on my autonumber field). When I execute the below code it will add blank records for each of the "LeadID"s, why is that?<BR>-----------------------------------------------------<BR>&#060;%@ language=VBScript %&#062;<BR>&#060;!-- #include file="" --&#062;<BR>&#060;HTML&#062;<BR>&#060;body&#062;<BR> &#060;%<BR>Dim lynrst<BR><BR>Set lynrst=Server.CreateObject("ADODB.Recordset")<BR>s qltext="SELECT * FROM tblOrders "<BR><BR>lynrst.Open sqltext, "DSN=Lead_Survey", adOpenKeyset, adLockOptimistic<BR><BR>For each value in Request.Form("LeadID")<BR><BR>&#039****add new record****<BR>lynrst.AddNew<BR><BR>&#039***** Begin requesting information ******<BR><BR> lynrst("FirstName")= Request.Form("FirstName")<BR> lynrst("LastName")= Request.Form("LastName")<BR> lynrst("Address")= Request.Form("Address")<BR> lynrst("City")= Request.Form("City")<BR> lynrst("State")= Request.Form("State")<BR> lynrst("ZipCode")= Request.Form("ZipCode")<BR> lynrst("WorkPhone")= Request.Form("WorkPhone")<BR> lynrst("HomePhone")= Request.Form("HomePhone") <BR> lynrst("EmailAddress")= Request.Form("EmailAddress")<BR>lynrst.Update<BR>N ext<BR>lynrst.Close<BR>%&#062;<BR>&#060;p&#062;&#0 60;%=Request.Form("LeadID")%&#062;&#060;/p&#062;<BR><BR>Thanks!<BR>&#060;/BODY&#062;<BR>&#060;/HTML&#062;<BR><BR><BR>If anyone could help it would be greatly appreciated!!<BR>-Linda<BR><BR><BR>

  2. #2
    Linda N. Guest

    Default RE: Adding Multiple Records via Checkboxes

    Does this one have everyone stumped, or is everyone just sick of beginners? Basically I think my big problem is with the SQL I need some sort of WHERE statement that I don&#039t have or something. "WHERE Request.Form("LeadID")=" & LeadID & ";" doesn&#039t work... I guess I will keep searching and if I find the answer I am looking for I will just reply to my own message for anyone else trying to do the same thing.<BR><BR>-Linda <BR>

  3. #3
    Join Date
    Dec 1969

    Default Code makes no sense...but...

    You do <BR><BR>For each value in Request.Form("LeadID")<BR><BR>so if that is a multiply-valued field (which I think is what you are saying in the next post), you will execute the loop several times. Fine. Good.<BR><BR>But *THEN* inside the loop, you do:<BR><BR>lynrst.AddNew<BR>lynrst("FirstName")= Request.Form("FirstName")<BR><BR>And that means that *EVERY SINGLE* newly added record will get *exactly* the same information!<BR><BR>Hmmm...but that&#039s exactly what you say *is* happening. And all the records are blank. Well, at least they are identical, as I would expect.<BR><BR>But why in the world would you want to add several records that are 100% identical???<BR><BR>Sorry, but I&#039m lost on this one.<BR><BR>******************<BR><BR>Since it&#039s Friday, and I probably won&#039t get back to this until Monday, I&#039m going to take a WAG (Wild Assed Guess) at what *maybe* you are trying to do.<BR><BR>On the form on the prior page, you have the checkboxes, all with the same name as you noted.<BR><BR>You *also* have a whole bunch of other fields, that look like this:<BR><BR>&#060;INPUT Type=??? Name="FirstName" Value="George"&#062;<BR>&#060;INPUT Type=??? Name="LastName" Value="Washington"&#062;<BR>... etc. ...<BR>and then<BR>&#060;INPUT Type=??? Name="FirstName" Value="Harry"&#062;<BR>&#060;INPUT Type=??? Name="LastName" Value="Truman"&#062;<BR>... etc. ...<BR><BR>Except *that* can&#039t be true, or you wouldn&#039t get blank records! Instead, you&#039d end up with the "FirstName" value in each record being a comma-separated list of all the INPUT "FirstName" fields! Such as "George, Harry, Dwight".<BR><BR>So since *that* is obviously not what you have, I will *hope* that what you actually have is:<BR><BR>&#060;INPUT Type=??? Name="FirstName1" Value="George"&#062;<BR>&#060;INPUT Type=??? Name="LastName1" Value="Washington"&#062;<BR>... etc. ...<BR>&#060;INPUT Type=??? Name="FirstName2" Value="Harry"&#062;<BR>&#060;INPUT Type=??? Name="LastName2" Value="Truman"&#062;<BR>... etc. ...<BR><BR>Is *that* what you have? I sure hope so! Because then the fix is dead easy!<BR><BR>You just need to change to this:<BR><BR>lynrst.AddNew<BR><BR>&#039***** Begin requesting information ******<BR><BR>lynrst("FirstName")= Request.Form("FirstName" & value)<BR>lynrst("LastName")= Request.Form("LastName" & value)<BR>lynrst("Address")= Request.Form("Address" & value)<BR>...<BR><BR>See? You need to ask for *precisely* the correct form field by name, and the name *includes* the "value" (presumably, numbers between 1 and whatever, but only those numbers matching checkboxes that the user clicked on) from your For Each.<BR><BR>As I said, this is a real WAG about what you are doing. <BR><BR>I think you would have gotten answers before now, but you fell into the usual trap: You did not show ALL YOUR CODE. In this case, the part you didn&#039t show was something that demonstrated what the page you are posting FROM consists of. So of course nobody can make a reasonable guess as to what is wrong. There is nothing wrong, per se, with the code you did show. It could even work, in a really weird circumstance (though I admit I don&#039t know *why* anybody would want it to).<BR><BR>So, hopefully, you will show *all* the relevant code next time.<BR><BR>Incidentally, if you do show the preceding page, it might be clearer to those reading if you did *not* show the ASP code that generates it. Instead, do a "View &#124 Source" in the browser, capture the generated HTML, and show the relevant portion of it (e.g., at least a couple of the checkboxes and the relevant matching fields).<BR><BR>Okay?<BR><BR>Good luck!<BR><BR><BR><BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts