Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to process html form data in vbscript

Posted on 2008-10-29
10
Medium Priority
?
1,917 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
TCP/IP Network Protocol Cheat Sheet

TCP/IP is a set of network protocols which is best known for connecting the machines that make up the Internet. The truth is that TCP/IP is one of the oldest network protocols and its survival is mainly based on its simplicity and universality.

 
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
 
LVL 82

Accepted Solution

by:
hielo earned 500 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

704 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