Click to See Complete Forum and Search --> : get data from a Form with different dynamic field names


youtoo
10-18-2006, 04:43 AM
Hey all

first of all I'll explain my app , look at the picture which I have attached

http://i11.tinypic.com/2qu3rlk.gif


I am designing a shopping site,
in the picture the #1 section is a check box behind product name that customer can select that product to buy in #2 section the customer can set quantity of the selected product

ok now codes
this is the code which I have used to pull out produts and categoris from database and show them on the page




<%
strSQL = "SELECT ProductCat.* FROM ProductCat"
rsCommon.Open strSQL, adoCon
Do while NOT rsCommon.EOF

strCatName = rsCommon("Catname")
strCatID = rsCommon("pcat_id")
%>
<table width="100%" border="0">
<tr>
<td height="25px" colspan="4"><b><%=strCatName%></b></td>
</tr>
<%
strSQL = "SELECT Products.* FROM Products WHERE Products.pcat = " & strCatID & " AND Products.active = 1"
rsProd.Open strSQL, adoCon

Do while NOT rsProd.EOF
strFName = rsProd("pname")
strPID = rsProd("id")
strPPrice = rsProd("pprice")
%>
<tr>
<td valign="middle" width="70%"><%=strPName%>*</td>
<td width="5px"><input class="inputTB" type="text" size="2" name="PROD<%=strPID%>" value="0" onBlur="if (qttverify(this,0,1)) calculate(document.order.P<%=strPID%>,0);"><input name="N<%=strPID%>" type="HIDDEN" value="<%=strPName%>"></td>
<td width="5px"><input type="checkbox" name="P<%=strPID%>" value="0_<%=strPPrice%>_0_<%=strPPrice%>" onClick="javscript:document.order.PROD<%=strPID%>.value='1'; calculate(this,0);"></td>
</tr>
<%
rsProd.MoveNext
Loop
rsProd.Close
Set rsProd = Nothing
%>
</table>
<%
rsCommon.MoveNext
Loop
rsCommon.Close
%>





ok now this will repeat the fields and the name of field is product ID so fields have different names
after posting I need two thing from this form
1. Product name from field :

<input name="N<%=strPID%>" type="HIDDEN" value="<%=strPName%>">

2. And this product quantity which has selected bu the customer from this field :

<input class="inputTB" type="text" size="2" name="PROD<%=strPID%>" value="0" onBlur="if (qttverify(this,0,1)) calculate(document.order.P<%=strPID%>,0);">

Note : because I am calculating price of the selected products with javascript I have to have different field names,

every thing is ok but I don't know how to retrieve data from this fields because these are dynamic and number of products and fields are different , and I don't know the name of the fields

please help me how to get data from this field

youtoo
10-18-2006, 04:45 AM
I found somthing

look at this





strSQL = "SELECT Products.* FROM Products WHERE Products.active = 1"
rsProd.Open strSQL, adoCon

Do while NOT rsProd.EOF

strPID = rsProd("id")


If request.form("PROD"&strPID) <> 0 then

strProd = request.form("N"&strPID) & "-" & request.form("PROD"&strPID)


response.Write strProd
End If


rsProd.MoveNext
Loop
rsProd.Close
Set rsProd = Nothing





it will write this

ProductName - 1
ProductName2 - 1
and ...

exactly what I wanted
but how can I insert them into database, I think I have to use array but I have tried that and it just store first record not all of them

what can I do?

etylocus
10-19-2006, 04:16 AM
Can you post the code you're using to insert the data into the DB?