Solved

How to process html form data in vbscript

Posted on 2008-10-29
10
1,864 Views
Last Modified: 2012-05-05
I'm trying to take input from html input boxes and insert the data into a access database.

The vbscript when executing it independently updates the database when i have hard coded values in it.

I'm trying to change it from static hard coded values to use the data input from an html form,
but I haven't been able to do it.

I tried changing these hard code values
objRecordSet("Name") = "vbscript"
objRecordSet("Comments") = "updateMe"

To
objRecordSet("Name") =  Request.Form("name")
objRecordSet("Comments") = Request.Form("comments")

but i get an error 'Object required: 'Request'

from what i can tell by googling i'm trying to put server side code in a client side application
and i can't use Request.Form()

Is there a way for a vbscript to use the post data of an html form?
Attached is the code for my 2 files

File updateDB.html----------------------------------
 

<html>

<head>

<title>Guestbook Form</title>

</head>

<body bgcolor="white" text="black">

<!-- Begin form code -->

<form name="form" method="post" action="add_new_record.vbs">

  Name: <input type="text" name="name" maxlength="20">  

  <br>

  Comments: <input type="text" name="comments" maxlength="60">

  <input type="submit" name="Submit" value="Submit">

</form>

<!-- End form code -->

</body>

</html>
 

File add_new_record.vbs----------------------------------

Const adOpenStatic = 3

Const adLockOptimistic = 3
 

Set objConnection = CreateObject("ADODB.Connection")

Set objRecordSet = CreateObject("ADODB.Recordset")
 

objConnection.Open _

    "Provider = Microsoft.ACE.OLEDB.12.0; " & _

        "Data Source = guestbook.accdb" 
 

objRecordSet.Open "SELECT * FROM tblComments" , _

    objConnection, adOpenStatic, adLockOptimistic
 

objRecordSet.AddNew

objRecordSet("Name") = Request.Form("name")

objRecordSet("Comments") = Request.Form("comments")

objRecordSet.Update
 

objRecordSet.Close

objConnection.Close

Open in new window

0
Comment
Question by:mitchguy
  • 5
  • 5
10 Comments
 
LVL 82

Expert Comment

by:hielo
ID: 22834724
>>action="add_new_record.vbs"
rename the file to asp and update your action:
action="add_new_record.asp"

request is an IIS Server Object so you need to submit to a server script (asp).
0
 

Author Comment

by:mitchguy
ID: 22834871
Well i didn't get the error, but the database didn't update either, it's as if
the Request.Form() call worked, but there was no data

Do you see anything i'm missing?
0
 
LVL 82

Expert Comment

by:hielo
ID: 22834936
Did you enclose the code in asp tags? Below is the COMPLETE file:
<%@language="vbscript"%>

<%

'File add_new_record.vbs----------------------------------

Const adOpenStatic = 3

Const adLockOptimistic = 3

 

Set objConnection = CreateObject("ADODB.Connection")

Set objRecordSet = CreateObject("ADODB.Recordset")

 

objConnection.Open _

    "Provider = Microsoft.ACE.OLEDB.12.0; " & _

        "Data Source = guestbook.accdb" 

 

objRecordSet.Open "SELECT * FROM tblComments" , _

    objConnection, adOpenStatic, adLockOptimistic

 

objRecordSet.AddNew

objRecordSet("Name") = Request.Form("name")

objRecordSet("Comments") = Request.Form("comments")

objRecordSet.Update

 

objRecordSet.Close

objConnection.Close

%>

Open in new window

0
 
LVL 82

Expert Comment

by:hielo
ID: 22834961
Also, you don't need SELECT to add a new query
<%

'File add_new_record.vbs----------------------------------

Const adOpenStatic = 3

Const adLockOptimistic = 3

 

Set objConnection = CreateObject("ADODB.Connection")
 

 

objConnection.Open _

    "Provider = Microsoft.ACE.OLEDB.12.0; " & _

        "Data Source = guestbook.accdb" 

 

objConnection.Execute "INSERT INTO [tblComments]( [Name],[Comments] ) VALUES( '" & Replace(Request.Form("name"),"'","''") & "','" & Replace(Request.Form("comments"),"'","''") & "'"

objConnection.Close

Set objConnection=Nothing

%>

Open in new window

0
 

Author Comment

by:mitchguy
ID: 22835114
Still can't get it to work.
You dont happen to have access 2007 do you?
The database is very basic.
It's created with access 2007 and as you can tell from the code named guestbook.accdb
and has one table named "tblComments" which has 3 fields
ID_no (AutoNumber)
Name(Text)
Comments(Text)

Is there an easy way to print to the screen from the asp file what values it's getting from the html page?
I don't know if this matters or not, but after clicking the submit button on the html page the asp page is then displayed in the browser. I'm not sure if that is supposed to happen or not?
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 82

Accepted Solution

by:
hielo earned 125 total points
ID: 22835218
>>after clicking the submit button on the html page the asp page is then displayed in the browser
Oh no! It sounds like you are NOT serving your html page from an IIS server. If I am not mistaken, you intend to put that page online. If so, you need to install IIS and run it from IIS.
0
 

Author Comment

by:mitchguy
ID: 22835352
Is IIS the only server that this would work with?  i have apache server installed
0
 

Author Comment

by:mitchguy
ID: 22835456
looks like i have IIS 5.1 installed already as well.
I will see what i can figure out
0
 
LVL 82

Expert Comment

by:hielo
ID: 22835910
>>looks like i have IIS 5.1 installed already as well.
Good.
0
 

Author Comment

by:mitchguy
ID: 22880206
Is there a particular folder structure that must be in order for this to work?

I have the folder with the files in it in the wwwroot folder, but it still
just displays the code in the browser when i try running it
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now