Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1929
  • Last Modified:

How to process html form data in vbscript

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
mitchguy
Asked:
mitchguy
  • 5
  • 5
1 Solution
 
hieloCommented:
>>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
 
mitchguyAuthor Commented:
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
 
hieloCommented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
hieloCommented:
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
 
mitchguyAuthor Commented:
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
 
hieloCommented:
>>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
 
mitchguyAuthor Commented:
Is IIS the only server that this would work with?  i have apache server installed
0
 
mitchguyAuthor Commented:
looks like i have IIS 5.1 installed already as well.
I will see what i can figure out
0
 
hieloCommented:
>>looks like i have IIS 5.1 installed already as well.
Good.
0
 
mitchguyAuthor Commented:
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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now