Hvad hedder felterne i din tabel?, hvor stor kan visitsnr være? Du får jo en hel masse felter som hedder tekst1, jeg ville nok lave dem dynamisk og så holde en hidden værdi så jeg vidste hvor mange der er, sådan her --- <form action="xxx.asp" method="post"> <% Visits = Cint(Request.Form("visitsnr")) %> <input type="hidden" name="antal" value="<%=Visits%>"> <% y = 1 Do While y <= Visits %> <table border="0" cellpadding="0" cellspacing="0"> <tr> <td><input type="text" name="tekst<%=y%>"></td> </tr> </table> <% y = y + 1 Loop %> <input type="submit" name="submit" value="Gem"> </form> --- på siden xxx.asp kan du så lave et loop if request.form("submit") <> "" then //database forbindelse sql = "Insert into din_tabel values (" for i=1 to request.form("antal") sql = sql & request.form("tekst"&i) & "," next sql = left(sql,len(sql)-1) & ")" conn.execute(sql) end if --- Det var et foreslag, men da felterne er dynamiske ved jeg ikke om du ønsker de skal ind i hvert sit felt i tabellen eller hvad de skal?
Hvis du kalder felterne det samme på siden, så burde Request.Form("tekst1") være en collection af værdier. Dvs. flg. kan måske bruges:
<%@ language="vbscript" %> <% if request.Form("cmdGO") <> "" then for each txt in request.Form("tekst") Response.Write(txt & "<br>") next end if %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" >
Jeg har siddet og rodet lidt med det og kan ikke rigtig få det til at virke. Jeg har udbygget min formular til dette:
<table border="0" cellpadding="3" cellspacing="0" align="center" width="700" id="border"> <tr> <td align="center" colspan="3"><font face="Verdana" size="1"><strong>Please fill in below any visits from medical consultants<br>you have received within the last 14 days</strong></font></td> </tr> <tr> <td colspan="3"><hr color="#000000" size="1" width="98%" noshade></td> </tr> <tr> <td colspan="3"> <form name="dato" method="post" action="answers.asp""> <% Visits = Cint(Request.Form("visitsnr")) %> <input type="hidden" name="antal" value="<%=Visits%>"> <% y = 1 Do While y <= Visits
Set rsDesease = Server.CreateObject("ADODB.Recordset") sql = "Select * From Desease" rsDesease.Open sql, Conn %> <table border="0" cellpadding="5" cellspacing="0" width="100%" align="center"> <tr align="center" valign="top"> <td width="20%"><font face="Verdana" size="1">Date of visit</font></td> <td width="20%"><font face="Verdana" size="1">Regarding which kind of desease?</font></td> <td width="20%"><font face="Verdana" size="1">From which company?</font></td> <td width="20%"><font face="Verdana" size="1">How many GP's Attended?</font></td> <td width="20%"><font face="Verdana" size="1">Was any trial products handed out?</font></td> </tr> <tr align="center" valign="top"> <td> <SELECT NAME="dateofvisit<%=y%>" id="submit"> <%For i = 0 To -14 step -1 response.write "<OPTION VALUE=""" & dateadd("d", i, date()) & """>" & dateadd("d", i, date()) & "</OPTION>" Next response.write "</SELECT>"%></td> <td> <SELECT NAME="kindofdesease<%=y%>" id="submit"> <% Do While Not rsDesease.EOF %> <option value="<%=rsDesease("Desease")%>"><%=rsDesease("Desease")%></option> <% rsDesease.Movenext Loop %> </select> </td> <td><input type="text" name="whichcompany<%=y%>" id="textbox"></td> <td><input type="text" name="howmanygps<%=y%>" id="textbox"></td> <td> <SELECT NAME="trialproducts<%=y%>" id="submit"> <option value="Yes">Yes</option> <option value="No">No</option> </select> </td> </tr> <tr> <td colspan="5"><hr color="#000000" size="1" noshade></td> </tr> </table> <% y = y + 1 Loop %> <table border="0" cellpadding="0" cellspacing="0" align="center"> <tr> <td><input type="submit" name="submit" value="Gem" id="submit"></td> </tr> </table> </form> </td> </tr> </table>
og prøver så at indsætte data i db'en med dette:
If Request.Form("submit") <> "" Then sql = "Insert Into Questions (DateOfVisit,KindOfDesease,WhichCompany,HowManyGPs,TrialProducts) Values ('" For i = 1 to Request.Form("antal") sql = sql & Request.Form("dateofvisit"&i) & "','" sql = sql & Request.Form("kindofdesease"&i) & "','" sql = sql & Request.Form("whichcompany"&i) & "','" Sql = Sql & Request.Form("howmanygps"&i) & "','" Sql = Sql & Request.Form("trialproducts"&i) & "','" next sql = left(sql,len(sql)-1) & "')" Conn.Execute sql End If
men får denne fejl:
Number of query values and destination fields are not the same.
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.