开发者

classic asp form handling

I have an "ancient" webpage that I need to instill some databasing capabalities into it, and I'm afraid I'm at a loss as I can't find a good enough resource on how to do that and how the queries goes as far as classic ASP.

so this is basically how it goes, I have a form validator which is written in jQuery, once the form is validated, I want to use a $.post request to send the data to a form processor (some sort of classic asp file).

I tried using Request.Form("field") but it isn't working. I tried even using a $.get request using Request.QueryString("field") and I have no 开发者_JS百科success there aswell.

some code:

Dim sConnection, objConn , objRS 
sConnection = "connection string" 
username = Request.QueryString("username")
sitename = Request.QueryString("site_name")
email = Request.QueryString("email")
comment = Request.QueryString("comment")
dataInsert = ("INSERT INTO larrydb_review (username, sitename, email, comment, rating) values (username, sitename, email, comment, rating)")
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open(sConnection) 

objConn.Execute dataInsert

I'm assuming that the SQL Query string isn't written correctly, but I afraid I haven't found where to write one properly using asp variables.

Any help will be greatly appreciated, Thank you.


If you are using the METHOD = POST in your form, to retrieve the data sent in your ASP page:

username = Request.form("username")
sitename = Request.form("site_name")
email = Request.form("email")
comment = Request.form("comment")

then to update the SQL Table you have to create a dynamic string as:

dataInsert = "INSERT INTO larrydb_review (username, sitename, email, comment, rating) values ('" & username & "', '" & sitename & "', '" & email & "', '" & comment & "', '" & rating & "')"

Also your variable sConnection = "connection string" must be properly fill with the connection string for your database like this example:

sConnection = "Provider=SQLNCLI.1;Password=YOUR_PASSWORD;Persist Security Info=True;User ID=YOU_USER_ID_FOR_DB;Initial Catalog=YOUR_DATABASE_NAME;Data Source=IP_YOUR_DB_SERVER;Use Regional Settings: Yes"


search Google Books. an example: http://books.google.com/books?id=LtdykpJvgXQC&pg=PA95&dq=asp+createobject.adodb.connection+insert.into&hl=en&ei=H0_rTbjqIMjiiAL_le3gCA&sa=X&oi=book_result&ct=result&resnum=1&ved=0CC0Q6AEwAA#v=onepage&q&f=false

build your INSERT string using the string concatenation operator "&":

query = "INSERT INTO bleah (foo, bar) VALUES ('" & myfoo & "', '" & mybar & "')"

books.google.com is a great resource for things like this. I haven't programmed classic ASP since the mid-90s.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜