473,325 Members | 2,480 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Dynamic Variable Array in ASP (Form Text Input)

I'm trying to adapt a PHP shopping cart code to ASP:

The cart outputs the SQL product list to a HTML a page where the client enters the quantity they want of each SKU:

<FORM ACTION="page.asp" METHOD=POST>
<INPUT TYPE="TEXT" NAME="SKU[123451]" SIZE="3" VALUE="">
<INPUT TYPE="TEXT" NAME="SKU[123452]" SIZE="3" VALUE="">
<INPUT TYPE="TEXT" NAME="SKU[123453]" SIZE="3" VALUE="">
<INPUT TYPE="TEXT" NAME="SKU[123454]" SIZE="3" VALUE="">
</FORM>

Is there a quick way (ie an array method) without having to parse the entire Request.Form string manually? PHP uses a foreach string that is arranged differently than ASP.

I need ASP code to loop through and find each SKU/QUANTITY in Request.Form to run SQL insert commands:

INSERT INTO product (QUANTITY, SKU) values (x, '123451')
INSERT INTO product (QUANTITY, SKU) values (x, '123452')
INSERT INTO product (QUANTITY, SKU) values (x, '123453')
INSERT INTO product (QUANTITY, SKU) values (x, '123454')

Thanks!
Aug 30 '07 #1
6 6796
markrawlingson
346 Expert 100+
I would use this...

Expand|Select|Wrap|Line Numbers
  1. <%
  2. For Each oItem In Request.Form
  3.      If InStr(oItem,"SKU") > 0 Then
  4.           sSQL = "INSERT INTO product (QUANTITY, SKU) values (" & Request.Form(oItem) & ", '" & oItem & "')"
  5.      End If
  6. NEXT
  7. %>
  8.  
oItem is the name of each object within the Request.Form object. So for your example, it would represent SKU[123451] - To get the data from that object you Request.Form(oItem)

It's basically a dynamic loop through everything that was submitted in the form on the previous page. I've put an If statement in there for you because you don't want to insert a new record into your database unless it's an actual item (if you had something like a hidden form field, or checkbox - it would throw an error)
Aug 30 '07 #2
Many thanks!

Is there a way to see that SKU[12345] is an array though without having to Left, Mid, or Right "SKU[" & "]" out of the variable?
Aug 30 '07 #3
markrawlingson
346 Expert 100+
You mean you want to detect whether the object has "SKU" within it.. like if you wanted to check SKU[123456] to see if it contained the word "SKU" ?

That's what Instr() does.

Instr(stringtocheck, string to search for)

Returns a numerical value indicating the amount of times your search term was found within the string.
Aug 30 '07 #4
No, just strip the SKU[] wrapper on the fly rather than like:

SKU = Replace(oItem,"SKU[","")
SKU = Replace(SKU,"]","")

PHP seems to be able to figure out that

SKU[12345]

is

SKU = "12345"

without all the manual parsing... and pairs it with the appropriate quantity.
Aug 30 '07 #5
It all seems so simply done in PHP:

foreach ($_REQUEST['pricing'] as $pricingID => $quantity) {
if (intval($quantity) > 0) {
$invoice->addRegistration($pricingID, intval($quantity));
}
}
Aug 30 '07 #6
markrawlingson
346 Expert 100+
That depends on the scenario really. For your situation if you wanted to strip the SKU[] and just keep the 123451 value.. my collegue and i wrote a nice function for it...

Expand|Select|Wrap|Line Numbers
  1.  
  2.   Function Val( sValuePrivate )
  3.     Set oRegExp = New RegExp
  4.     oRegExp.Pattern = "[^0123456789\.]"
  5.     oRegExp.IgnoreCase = True
  6.     oRegExp.Global = True
  7.     Val = Abs( oRegExp.Replace( "0" & sValuePrivate, "" ) )
  8.     Set oRegExp = Nothing
  9.   End Function
  10.  
  11.  
This function basically tears out all string values and leaves you with just a numerical value. For instance.. SKU[123456] will return as 123456. "hello my name as mark" will return as 0 because it does not contain a numerical value.
Aug 30 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Nick | last post by:
Loop to create an array from a dynamic form. I'm having trouble with an application, and I'll try to explain it as clearly as possible: 1. I have a form with two fields, say Apples and...
4
by: Dan | last post by:
Can anyone offer suggestions on how to do this or if it is possible? I have a form that uses a drop down box and 2 text fields. What I am trying to do is have the value of each text box set by...
1
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to...
2
by: assgar | last post by:
Hi Developemnt on win2003 server. Final server will be linux Apache,Mysql and PHP is being used. I use 2 scripts(form and process). The form displays multiple dynamic rows with chechboxs,...
26
by: Jerim79 | last post by:
I need to create a form that takes a number that the user enters, and duplicates a question the number of times the user entered. For instance, if the customer enters 5 on the first page, when...
7
by: Jerim79 | last post by:
My situation is that I have a form that asks the user for a number. Next, I execute a while loop that displays a group of questions the amount of times the customer entered. For instance, the loop...
6
by: sathyashrayan | last post by:
Dear Group, Please look at the following demo link. http://www.itsravi.com/demo/new_pms/admin/addproject.php
0
bmallett
by: bmallett | last post by:
First off, i would like to thank everyone for any and all help with this. That being said, I am having a problem retrieving/posting my dynamic form data. I have a form that has multiple options...
4
by: Michael Munch | last post by:
Hi I want to read the value of af text-field, create dynamic, in a form. Se below a small test-site to do that (but readning fails): I use the function Test_Read for reading the value from the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.