...

View Full Version : Insert 321(three to one)



sasha85
10-02-2007, 03:09 PM
pSku1 = getUserInput(request.form("sku1"),20)
pDescription1 = getUserInput(request.form("description1"),100)
pYoutube1 = getUserInput(request.form("youtube1"),400)
pDetails1 = getUserInput(request.form("details1"),2000)
pSku2 = getUserInput(request.form("sku2"),20)
pDescription2 = getUserInput(request.form("description2"),100)
pYoutube2 = getUserInput(request.form("youtube2"),400)
pDetails2 = getUserInput(request.form("details2"),2000)
pSku3 = getUserInput(request.form("sku3"),20)
pDescription3 = getUserInput(request.form("description3"),100)
pYoutube3 = getUserInput(request.form("youtube3"),400)
pDetails3 = getUserInput(request.form("details3"),2000)


mySQL="INSERT INTO products (sku, youtube, description, details) VALUES ('" &pSku& "','" &pYoutube& "','" &pDescription& "','" & pDetails& "')"
call updateDatabase(mySQL, rstemp, "insert1")

that's shortly the way i'm inserting new records...
using mysql and asp functions...

but the prob is that inserting only one record every time...
if i got data for 3 records how can i make it at once?
to add 3 new records in some given order into the db?

Basscyst
10-02-2007, 09:01 PM
Well, you can save yourself some time by naming your form elements the same regardless if they are of the same record.

So rather than having pYoutube1,pYoutube2,pYoutube3, just name them all pyouTube.

Then when they submit to the server, you'll have a collection you can loop through for each set of data. Something like this for example:



For i = 1 To Request("e_name").Count
ExecSQL("INSERT INTO [EFHA].dbo.Employers (" &_
"LoanID," &_
"BorrowerID," &_
"SelfEmployedIndicator," &_
"_Name," &_
"_Street," &_
"_City," &_
"_State," &_
"_Zip," &_
"StartDate," &_
"EndDate," &_
"MonthlyIncome," &_
"CurrentFlag," &_
"PrimaryIndicator," &_
"PositionDescription," &_
"_Phone) VALUES(" &_
"'" & loanid & "'," &_
"'" & bor & "'," &_
"'" & Trim(NoQuote(Request("selfemployed")(i))) & "'," &_
"'" & Trim(NoQuote(Request("e_name")(i))) & "'," &_
"'" & Trim(NoQuote(Request("e_address")(i))) & "'," &_
"'" & Trim(NoQuote(Request("e_city")(i))) & "'," &_
"'" & Trim(NoQuote(Request("e_state")(i))) & "'," &_
"'" & Trim(NoQuote(Request("e_zip")(i))) & "'," &_
"'" & Trim(NoQuote(Request("e_start")(i))) & "'," &_
"'" & Trim(NoQuote(Request("e_end")(i))) & "'," &_
"" & Trim(NoQuote(Request("e_salary")(i))) & "," &_
"'" & Trim(NoQuote(Request("current_employer")(i))) & "'," &_
"'" & p_ind & "'," &_
"'" & Trim(NoQuote(Request("e_position")(i))) & "," & Trim(NoQuote(Request("e_title")(i))) & "," & Trim(NoQuote(Request("e_biztype")(i))) & "'," &_
"'" & Trim(NoQuote(Request("e_phone")(i))) & "')")
Next


Hope that helps,

Basscyst

sasha85
10-02-2007, 11:48 PM
but on the pre page-from where i am typing handly the data for 3 records i write it in 3 diffrent <input type=text name=...
how can i send it all into one request.form?

=i got 3 links for you tube and not one...
pYoutube1,pYoutube2,pYoutube3, not only pyouTube.

what is NoQuote?


is it possiable with Execute? cause i never use Execute and all my <input type=text -for all 3 records are on one page

Basscyst
10-03-2007, 12:20 AM
NoQuote() and ExecSQL() are my own function for handling the replacement of single quotes and the connection object repectfully.

An example of what I'm trying to convey:


<form method="post" action="somepage.asp">
<input type="text" name="somelink" />
<input type="text" name="somelink" />
<input type="text" name="somelink" />
<input type="text" name="somelink" />
<input type="text" name="somelink" />
<input type="submit" value="Submit" />
</form>


When this form submits to somepage.asp the serverside code (simplified)would look something like this:



For i = 1 To Request.Form("somelink").count
sqlstr="INSERT INTO sometable (somecolumn) VALUES('" & Request.Form("somelink")(i) & "')"
oconn.Execute(sqlstr)
Next


Make sense?

sasha85
10-03-2007, 12:58 AM
if i will swrite all my input fields with the same name="somelink"
i willl get a string with spaces between or only the last one...?

when the insert will start it will ask for
(somelink")(1)
(somelink")(2)
(somelink")(3)
...

:confused:

Basscyst
10-03-2007, 01:28 AM
dim somelink
somelink=Request("somelink")


The variable somelink will hold a comma delimited string, but will not be recognized as a collection.

So this would not work:



For i = 1 To somelink.Count
x=somelink(i)
Next


However this will work:



For i = 1 To Request("somelink").Count
x=Request("somelink")(i)
Next


Did that answer your question?

Basically when you request a form element with multiple inputs of the same name it creates an array (collection) containing all the values of the elements with that name. However for some reason unknown to me, when you assign that collection to a variable it becomes a string. . .

sasha85
10-03-2007, 01:44 AM
<form method="post" name="addCateg" action="addshablonExe.asp">
<input type="text" name="new" />
<input type="text" name="new" />
<input type="text" name="new" />
<input type="text" name="new" />
<input type="text" name="new" />
<input type="submit" value="Submit" />




dim i
For i = 1 To Request.Form("new").count
mySQL="INSERT INTO badwords (words) VALUES('" & Request.Form("new")(i) & "')"
rstemp.Execute(mySQL)
Next

call updateDatabase(mySQL, rstemp, "cooldd.asp")

response.redirect "message.asp?message="& Server.Urlencode("added")



call closeDb()

sasha85
10-03-2007, 02:11 AM
WHY IT'S WORKING WHEN I DEL THIS LINE

rstemp.Execute(mySQL)

somehow even if i will fill only 2 of the inputs...it still opens a holl 5 records...
how i can tell the Request.Form("new").count to count only full inputs?

Basscyst
10-03-2007, 02:23 AM
Hmm?



dim i
For i = 1 To Request.Form("new").count
mySQL="INSERT INTO badwords (words) VALUES('" & Request.Form("new")(i) & "')"
Next

call updateDatabase(mySQL, rstemp, "cooldd.asp")
call closeDb()
response.redirect "message.asp?message="& Server.Urlencode("added")


You're saying it's working when you remove the line you stated, so it looks as above? All data actually saving into your database? I don't know what your updateDatabase() function is doing, but it doesn't look like it should be working in it's current state. If it is, well . . .cool.

This seems more likely to work, though again I'm not sure exactly what those functions do as I have not seen that code:



dim i
For i = 1 To Request.Form("new").count
mySQL="INSERT INTO badwords (words) VALUES('" & Request.Form("new")(i) & "')"
call updateDatabase(mySQL, rstemp, "cooldd.asp")
Next
call closeDb()
response.redirect "message.asp?message="& Server.Urlencode("added")

sasha85
10-03-2007, 03:03 AM
what can you say about the count?
it's counting all 5 even if some of them empty...
how i can set to only fulfilled request.forms?

Spudhead
10-03-2007, 01:47 PM
how i can set to only fulfilled request.forms?

Each time you generate a SQL statement in that loop, you're getting one of the values from your form, right? This bit:


Request.Form("new")(i)

Is getting a value from your form.

IF that value equals an empty string
you don't need to fire a SQL statement,
ELSE
you do need to fire a SQL statement.
END IF


:thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum