473,398 Members | 2,393 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,398 software developers and data experts.

INSERT DATA FROM MULTIPLE TEXTAREAS IN THE FORM TO THE DATABASE

HELLO,

I AM A NEW BII TO ASP,AND I NEED HELP ON THIS ISSUE.
I HAVE A .ASP FORM WHICH IS ALREADY BUILT WITH 5 QUESTIONS AND 5 TEXTAREAS
RESPECTIVELY.THESE 5 QUESTIONS ARE NOT FIX,THERE WILL BE MORE ADDITION.

ITS BASICALLY A SURVEY FORM.

I HAVE CREATED A TABLE WITH 3 FIELDS :QUESTION ID,RESPONSE IN TEXTAREA, AND
DATE.
AND THESE 3 ARE TO BE INSERTED IN DATABASE VIA THIS FORM.

I HAVE TO 1ST COUNT /PARSE HOW MANY TEXTAREAS ARE THERE IN THIS FORM,THEN
EXTRACT EACH TEXTAREA ID.

AND THEN FINALLY I HAVE TO INSERT QESTION ID,TEXTAREA RESPONSE TO THE DATABSE.

I WILL BE REALLY GRATEFUL IF SOMEBODY CAN HELP ME TO PROCEED THROUGH IT.

I HAVE BEEN ADVICE TO USE SOME FUNCTIONS TO IMPLEMENT THIS

HERE IS THE LINK OF THIS FORM
http://localhost/testasp/SurveyResponse.asp

THANK YOU

WILL BE EGARLY WAITING FOR SOME REPLY


Jul 10 '08 #1
8 5103
Easiest way is to just number the fields.

Example:

<FORM Action="processAnswers.asp" Method=POST>
Question: How much is 3 + 7 * 10 ?
Answer: <TEXTAREA Name="answer1"></TEXTAREA>
Question: What are your favorite foods?
Answer: <TEXTAREA Name="answer2"></TEXTAREA>
Question: Describe the effects of moonlight on the flight of Monarch
butterflies:
Answer: <TEXTAREA Name="answer3"></TEXTARE>
....
<INPUT Type=Submit Value="Submit my answers">
</FORM>

And then you "processAnswers.asp" page simply does this:

<%
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "...your connection string ..."

For answerNumber = 1 TO 3
answer = Request("answer" & answerNumber)
If answer <"" Then
SQL = "INSERT INTO answers( user, answerNumber, answer ) " _
& " VALUES(" & userid & "," & answerNumber & "," _
& "'" & Replace(answer, "'", "''") & "')"
conn.Execute SQL
End If
Next
conn.Close
%>

Jul 10 '08 #2

Well first of all thank a ton for reply.
Here is the link of the page where I have to perform insertion of data in
the databse.http://www.smartcharlotte2050.com/YourThoughts.asp

I have been told to write some function that will traverse through the form
and will count textareas and also search for each textareaID and insert it
in the question ID column of the table.

Is there any way ,on how to traverse through the form.asp source code and
count textareas and insert its content in database.

Thanks again.
And again expecting a quick response.


"Old Pedant" wrote:
Easiest way is to just number the fields.

Example:

<FORM Action="processAnswers.asp" Method=POST>
Question: How much is 3 + 7 * 10 ?
Answer: <TEXTAREA Name="answer1"></TEXTAREA>
Question: What are your favorite foods?
Answer: <TEXTAREA Name="answer2"></TEXTAREA>
Question: Describe the effects of moonlight on the flight of Monarch
butterflies:
Answer: <TEXTAREA Name="answer3"></TEXTARE>
...
<INPUT Type=Submit Value="Submit my answers">
</FORM>

And then you "processAnswers.asp" page simply does this:

<%
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "...your connection string ..."

For answerNumber = 1 TO 3
answer = Request("answer" & answerNumber)
If answer <"" Then
SQL = "INSERT INTO answers( user, answerNumber, answer ) " _
& " VALUES(" & userid & "," & answerNumber & "," _
& "'" & Replace(answer, "'", "''") & "')"
conn.Execute SQL
End If
Next
conn.Close
%>
Jul 10 '08 #3
Is there any way ,on how to traverse through the form.asp source code and
count textareas and insert its content in database.
Yes. Use the code I gave you.

What did you THINK it was doing????

It's doing *EXACTLY* that.

But forget ID's on the fields. IDs don't matter in ASP code. Use names, as
I showed you.

Did you even TRY that code???
Jul 10 '08 #4
Using the FORM you actually show there, you would just alter my code to

<%
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "...your connection string ..."

For answerNumber = 1 TO 4
answer = Request("Your Thoughts Q" & answerNumber)
If answer <"" Then
SQL = "INSERT INTO answers( answerNumber, answer ) " _
& " VALUES(" & answerNumber & "," _
& "'" & Replace(answer, "'", "''") & "')"
conn.Execute SQL
End If
Next
conn.Close
%>

You didn't bother to show us the schema of your DB table, so I just assumed
TABLE: answers
answerNumber int
answer text
Jul 10 '08 #5
Old Pedant wrote:
>Is there any way ,on how to traverse through the form.asp source
code and count textareas and insert its content in database.

Yes. Use the code I gave you.

What did you THINK it was doing????

It's doing *EXACTLY* that.

But forget ID's on the fields. IDs don't matter in ASP code. Use
names, as I showed you.

Did you even TRY that code???
Cmon, pedant, hop to it. He's expecting a quick response. Stop dithering now
.... :-)

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 10 '08 #6
"Bob Barrows [MVP]" wrote:
Cmon, pedant, hop to it. He's expecting a quick response. Stop dithering now
.... :-)
No fair! Making the people around me give me strange looks for ROTFLMAO.

Too funny! Needed that!
Jul 10 '08 #7
Thank You
And also,sorry for thanking you late,

BUT I am getting error in the insert statement, and i am not being able to
solve it.

2ndly in this form,later more questions will be added, so is there any
simple way to count the # of textareas and then use it in for loop.

After my long search on google I found one thing...there is a class define

Class UtilityObj
Private _name As String
Private _value As String
Public Sub New(ByVal Name As String,ByVal Value As int)
_name = Name
_value = Value
End Sub
Public Property Name() As String
Get
Return _name
End Get
Set(ByVal Value As String)
_name = Name
End Set
End Property
Public Property Value() As String
Get
Return (_value)
End Get
Set(ByVal Value As String)
_value = Value
End Set
End Property
End Class
then using this function the name and ID is being inserted in the database

Funtion LoopingControls(oControl As Control)
Dim frmCtrl As Control
oArrayList = New ArrayList
For each frmCtrl in oControl.Controls
If TypeOf frmCtrl Is TextArea Then

Call FunctionDB(db)

End If
If frmCtrl.HasControls Then
LoopingControls(frmCtrl)
End If
Next
End Function
This is the function which will do database connection.

Function FunctionDB(db)

Set db=Server.CreateObject ("ADODB.Connection")

db.Open "DSN=surveydsn;User ID=dbo_sage;Password=sage;"

SQL = "INSERT INTO survey ( i, res ) "
& " VALUES(" & i & ","
& "'" & Replace(res, "'", "''") & "')"
db.Execute SQL
db.Close
db.Execute(VarQuery)
End Function

Now the thing is I am messed up with this, I have all the logic to
perform,but not being able to assemble it.
Lastly somebody told me to use Microsoft Visual studio 6, well i am not
being able to open interdev as I dont have FrontPage 98 server extension and
also Its not available on net free to download,
Hope you will again help me.

Thank again for your support,it really helped me.

"Old Pedant" wrote:
Using the FORM you actually show there, you would just alter my code to

<%
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "...your connection string ..."

For answerNumber = 1 TO 4
answer = Request("Your Thoughts Q" & answerNumber)
If answer <"" Then
SQL = "INSERT INTO answers( answerNumber, answer ) " _
& " VALUES(" & answerNumber & "," _
& "'" & Replace(answer, "'", "''") & "')"
conn.Execute SQL
End If
Next
conn.Close
%>

You didn't bother to show us the schema of your DB table, so I just assumed
TABLE: answers
answerNumber int
answer text

Jul 14 '08 #8
>>RE: INSERT DATA FROM MULTIPLE ...

=?Utf-8?B?T2xkIFBlZGFudA==?= wrote on 19 jul 2008 in
microsoft.public.inetserver.asp.general:
<%
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "...your connection string ..."

For answerNumber = 1 TO 99
answer = Trim( "" & Request("Your Thoughts Q" & answerNumber) )
If answer <"" Then ' *** SKIPS BLANK ANSWERS! ***
SQL = "INSERT INTO answers( answerNumber, answer ) " _
& " VALUES(" & answerNumber & "," _
& "'" & Replace(answer, "'", "''") & "')"
conn.Execute SQL
End If
Next
conn.Close
%>
Nice code, gives me 99 chances to do a SQL-injection i one go!

And both in post and in querystring!
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 19 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Jack | last post by:
I have a text file of data in a file (add2db.txt) where the entries are already entered on separate lines in the following form: INSERT INTO `reviews` VALUES("", "Tony's", "Lunch", "Great...
3
by: jason | last post by:
How does one loop through the contents of a form complicated by dynamic construction of checkboxes which are assigned a 'model' and 'listingID' to the NAME field on the fly in this syntax:...
8
by: Sans Spam | last post by:
Greetings! I have a table that contains all of the function permissions within a given application. These functions are different sections of a site and each has its own permissions (READ, WRITE,...
5
by: SSP | last post by:
Dear ASP.NETers, How would I insert multiple rows of data from a web form? Are there any tute's and stuff around. Couldn't find any myself. Thanks in advance. SSP
12
by: shank | last post by:
I'm trying to use online samples for submitting multiple records from ASP into a stored procedure. Failing! Through the below form, a user could be submitting many records at a time. I'm not...
1
by: phpCodeHead | last post by:
I know that this sounds like something overly complex - because it is. However, if I can keep the user interface the way it is, my users will be ultra happy! That is the goal... In general, this...
11
by: TechnoAtif | last post by:
INSERT AND UPDATE MULTIPLE CHECKBOX DATA USING PHPMYSQL OR JAVASCRIPT Hi All I want to check the multiple checkboxes update them after revisiting that page. I am taking the name as...
11
by: dba | last post by:
Have been displaying data from database using html for some time but just recently trying to display data back to "form". Can't find answer. <form method="post" action="<?php echo $PHP_SELF;?>">...
2
by: PHPstarter | last post by:
Hi guys. I have 3 textareas, and I have a button to clear them. I used a standard form with onlick="document.formname.textareaname.value = '';"> But it stopped working when there was added more...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...
0
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...
0
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...
0
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,...

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.