Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    Regular Coder
    Join Date
    Sep 2007
    Posts
    179
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Insert 321(three to one)

    Code:
    Code:
    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?
    By the time u recognize this moment, This moment will be gone.

  • #2
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    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:

    Code:
    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
    Helping to build a bigger box. - Adam Matthews

  • #3
    Regular Coder
    Join Date
    Sep 2007
    Posts
    179
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Lightbulb mm

    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
    Last edited by sasha85; 10-02-2007 at 11:05 PM.
    By the time u recognize this moment, This moment will be gone.

  • #4
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    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:
    Code:
    <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:

    Code:
    For i = 1 To Request.Form("somelink").count
    	sqlstr="INSERT INTO sometable (somecolumn) VALUES('" & Request.Form("somelink")(i) & "')"
    	oconn.Execute(sqlstr)
    Next
    Make sense?
    Last edited by Basscyst; 10-02-2007 at 11:24 PM.
    Helping to build a bigger box. - Adam Matthews

  • #5
    Regular Coder
    Join Date
    Sep 2007
    Posts
    179
    Thanks
    4
    Thanked 0 Times in 0 Posts

    if

    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)
    ...

    By the time u recognize this moment, This moment will be gone.

  • #6
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    Code:
    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:

    Code:
    For i = 1 To somelink.Count
     x=somelink(i)
    Next
    However this will work:

    Code:
    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. . .
    Last edited by Basscyst; 10-03-2007 at 12:32 AM.
    Helping to build a bigger box. - Adam Matthews

  • #7
    Regular Coder
    Join Date
    Sep 2007
    Posts
    179
    Thanks
    4
    Thanked 0 Times in 0 Posts

    yes but it did not solve the prob

    Code:
    <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" />
    Code:
    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()
    Last edited by sasha85; 10-03-2007 at 12:52 AM.
    By the time u recognize this moment, This moment will be gone.

  • #8
    Regular Coder
    Join Date
    Sep 2007
    Posts
    179
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Ok! Now Its Workin

    WHY IT'S WORKING WHEN I DEL THIS LINE
    Code:
    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?
    Last edited by sasha85; 10-03-2007 at 01:22 AM.
    By the time u recognize this moment, This moment will be gone.

  • #9
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    Hmm?

    Code:
    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:

    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")
    Last edited by Basscyst; 10-03-2007 at 01:48 AM.
    Helping to build a bigger box. - Adam Matthews

  • #10
    Regular Coder
    Join Date
    Sep 2007
    Posts
    179
    Thanks
    4
    Thanked 0 Times in 0 Posts

    you right...the update before the "next"

    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?
    By the time u recognize this moment, This moment will be gone.

  • #11
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    Quote Originally Posted by sasha85 View Post
    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:

    Code:
    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




  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •