Solved

How to process html form data in vbscript

Posted on 2008-10-29
10
1,887 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
Industry Leaders: 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!

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

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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 how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

738 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