how to quickly insert a record

This is a discussion on "how to quickly insert a record" within the Classic ASP section. This forum, and the thread "how to quickly insert a record are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > Classic ASP

Notices


Closed Thread
 
LinkBack Thread Tools
  #1 (permalink)  
Old Oct 29th, 2003, 08:25
gab gab is offline
New Member
Join Date: Oct 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
how to quickly insert a record

Hi, I would like to quickly insert a record in a database, collecting values from a form.
I can do it if I use method GET but I can't find how to do it with POST

Here is the code I use:

...
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & server.MapPath("/mdb-database/" &dbname),,dbpassword
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open tablename, conn, 3, 3
rs.AddNew
'call metpost
call metget
rs.Update

Sub metpost
for i = 1 to (Request.Form.Count() -1)
strTemp = "rs("""&Request.Form.Key(i)&""")="&Request.Form.It em(i)
Response.write strTemp&"-"&rs(i)&"
"
Execute(strTemp)
next
End sub

Sub metget
For Each Item In Request.querystring
strTempb = "Itemb = Request.querystring(""" & Item & """)"
Execute(strTempb)
if Itemb<>"" then
strTemp = "rs("""&Item&""")= Request.querystring(""" & Item & """)"
Execute(strTemp)
End if
Next
End sub
...

If I use it like this it works, if I change the method I post the data (from GET to POST) and uncomment the line "call metpost" and of course comment the line "call metget" it doesn't work!
If I just check the "strTemp" it prints the right values, ex. rs("name")=gabriele.

It seems that "Execute(strTemp)" works only with GET, but sounds impossible.

Please help

Thanks a lot,
Gabriele (Italy)

  #2 (permalink)  
Old Oct 29th, 2003, 09:53
Highly Reputable Member
Join Date: Jul 2003
Location: Ipswich, UK
Posts: 690
Thanks: 0
Thanked 0 Times in 0 Posts
did you change the actual method used by the form?

form method=GET

form method=POST

??:
  #3 (permalink)  
Old Oct 29th, 2003, 10:35
gab gab is offline
New Member
Join Date: Oct 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Yes, sure.
  #4 (permalink)  
Old Oct 30th, 2003, 11:21
Highly Reputable Member
Join Date: Jul 2003
Location: Ipswich, UK
Posts: 690
Thanks: 0
Thanked 0 Times in 0 Posts
and that didnt fix the problem?
  #5 (permalink)  
Old Oct 31st, 2003, 14:30
New Member
Join Date: Oct 2003
Location: United Kingdom
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
When you use POST you need to change the sub metget() to use Request.Form, not Request.QueryString
  #6 (permalink)  
Old Oct 31st, 2003, 18:28
gab gab is offline
New Member
Join Date: Oct 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Everything was set correctly.

When I use "GET">
> form page
...
<form method="get" ...>
...

> script page
...
rs.AddNew
'call metpost
call metget
rs.Update
...

########################

When I use "POST">
> form page
...
<form method="post" ...>
...

> script page
...
rs.AddNew
call metpost
'call metget
rs.Update
...
#############

I fixed it this way, and now it works:
> script page

Sub metpost
for each key in Request.Form
if key <>"Submit" then
rs(key) = Request.Form(key)
end if
next
End sub

I don't know why the EXECUTE command didn't work, but what's important is that now I can do what I want.
Thanks guys.
Closed Thread

Tags
quickly, insert, record

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Insert help air duster Classic ASP 13 Jan 12th, 2006 08:38
Insert record in mysql djme Databases 1 Dec 24th, 2005 01:42
insert record accessman Databases 1 Oct 15th, 2005 01:12
Insert Record redkyna Classic ASP 11 Aug 25th, 2004 22:46


All times are GMT. The time now is 20:53.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43