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.
|
|
|
|
|
![]() |
||
how to quickly insert a record
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
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) |
|
|
|
|||
|
did you change the actual method used by the form?
form method=GET form method=POST |
|
|||
|
Yes, sure.
|
|
|||
|
and that didnt fix the problem?
|
|
|||
|
When you use POST you need to change the sub metget() to use Request.Form, not Request.QueryString
|
|
|||
|
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. |
![]() |
| Tags |
| quickly, insert, record |
| Thread Tools | |
|
|
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 |