473,791 Members | 3,251 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamic Variable Array in ASP (Form Text Input)

4 New Member
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.as p" 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 6882
markrawlingson
346 Recognized Expert Contributor
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(oI tem)

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
brainlpb
4 New Member
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 Recognized Expert Contributor
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(stringtoc heck, 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
brainlpb
4 New Member
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
brainlpb
4 New Member
It all seems so simply done in PHP:

foreach ($_REQUEST['pricing'] as $pricingID => $quantity) {
if (intval($quanti ty) > 0) {
$invoice->addRegistratio n($pricingID, intval($quantit y));
}
}
Aug 30 '07 #6
markrawlingson
346 Recognized Expert Contributor
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
4082
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 Oranges. The user selects from a drop down menu, between 1-10 of each and clicks submit. The resulting page will display a NEW form, with rows and a list of fields for the amount of each items selected.
4
6316
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 the choice from the drop down box. Something like: <form name="populatefrm" id="contactfrm" method="post"
1
17675
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 Create a Dynamic Crosstab Report PRODUCT :Microsoft Access PROD/VER:1.00 1.10 OPER/SYS:WINDOWS
2
7053
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, input box for units of service, description of the service and each row has its own dropdown list of unit fees that apply. Each dynamically created row will return 3 values fee1_choice, fee1_unit and fee1_money. Note The above informaton is...
26
2815
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 they press next the form generates "How old are you?" 5 times on the page. The customer will answer all 5 questions then press next. Finally, all the local variables get dynamically created and written to a database. I have already taken care of...
7
3529
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 looks this: while ($Number!=0){ <input type="radio" name="Age" value="20-30">20-30 <input type="radio name="Age" value="30-40">30-40 <input type="radio name"Age" value="40-50">40-50 $Number--;
6
2500
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
3396
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 within options. I have everything being dynamically named from the previously dynamically named element. (I hope this makes sense.) I am not able to retrieve any of the dynamically created values. I can view them on the source page but can't pull them...
4
4892
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 dynamic create text-field "txtName". I thanks...
0
9669
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10428
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10207
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10156
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9997
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9030
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5435
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5559
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3718
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.