Solved

database connection

Posted on 2007-03-29
6
188 Views
Last Modified: 2013-11-19
I am trying to collect information from a web page and send the information to a database. I have a database on our server machine and I am able to get the database to connect to the web page, but I am not able to get the information to go to the database when the submit button is clicked. I have tried this in both front page and in visual web developer and neither of them are working. In front page I have just gone to the form properties to connect it, and I am still trying to figure out visual web developer, so the only code I have for the submit button is what makes the button. How do I set it up so that the information will be sent to the server. I am able to get the information to send to an access database, just not the server database. Here is the code from front page.
<form action="--WEBBOT-SELF--" method="POST">
<!--webbot bot="SaveDatabase" SuggestedExt="asp" S-DataConnection="address" S-RecordSource="address" S-Form-Fields="First_Name Last_Name City Zip State Address" S-Form-DBFields="First_Name Last_Name City Zip State Address" -->First Name<input type="text"name"First_name" name="First_Name" size="19"/><br>
Last Name<input type="text"name"First_name" name="Last_Name" size="20"/><br>
Address<input type="text"name"First_name" name="Address" size="30"/><br>
City<input type="text"name"First_name" name="City" size="10"/><br>
State<input type="text"name"First_name" name="State" size="10"/><br>
Zip<input type="text"name"First_name" name="Zip" size="10"/><br>
&nbsp;
<input type="submit" name="Submit" value="Submit">
</form>
0
Comment
Question by:delta179
  • 3
6 Comments
 
LVL 29

Accepted Solution

by:
rdivilbiss earned 500 total points
ID: 18818962
When FrontPage builds a WEBBOT-SELF page, it creates and process your form via ASP.

It is far better, and much easier to use ASP directly to process your form than to use FrontPage's built in method.  (Not to mention FP was orphaned in 1999, so your pool of available troubleshooters goes down considerably.)

However, FrontPage may process your form correctly if your remove all the duplicate field names in your form.

Each of your form fields has two names, the first being FirstName, so it is entirely likely that the receiving page is getting all the form field submitted as a comma delimited string with the name FirstName.

e.g. City<input type="text"name"First_name" name="City" size="10"/><br>

should be: City<input type="text" name="City" size="10"/><br>

Also, you should never name your submit button "Submit", make the name="bSubmit", that is unrelated to your current problem, but if you ever do JavaScript validation, it will be a problem.

So thry this first and make sure it is saved as an ASP page and not a HTM page.


<form action="--WEBBOT-SELF--" method="POST">
<!--webbot bot="SaveDatabase" SuggestedExt="asp" S-DataConnection="address" S-RecordSource="address" S-Form-Fields="First_Name Last_Name City Zip State Address" S-Form-DBFields="First_Name Last_Name City Zip State Address" -->
First Name<input type="text" name="First_Name" size="19"/><br>
Last Name<input type="text"name="Last_Name" size="20"/><br>
Address<input type="text" name="Address" size="30"/><br>
City<input type="text" name="City" size="10"/><br>
State<input type="text" name="State" size="10"/><br>
Zip<input type="text" name="Zip" size="10"/><br>
&nbsp;
<input type="submit" name="bSubmit" value="Submit">
</form>

0
 
LVL 29

Expert Comment

by:rdivilbiss
ID: 18819110
If you want to cut through all the widget crap, this is all you need.

Page one -- form.htm
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Form Page ASP</title>
</head>

<body>
<form action="submitForm.asp" method="post">
First Name<input type="text" name="First_Name" size="19"/><br>
Last Name<input type="text"name="Last_Name" size="20"/><br>
Address<input type="text" name="Address" size="30"/><br>
City<input type="text" name="City" size="10"/><br>
State<input type="text" name="State" size="10"/><br>
Zip<input type="text" name="Zip" size="10"/><br>
&nbsp;
<input type="submit" name="bSubmit" value="Submit">
</form>
</body>

</html>



Page two - submitForm.asp (change the table, database, and connection details to suit)
<!--METADATA TYPE="typelib" uuid="00000205-0000-0010-8000-00AA006D2EA4" -->
<%
Dim First_Name, Last_Name, City, Zip, State, Address

fFirst_Name = Request.Form("First_Name")
fLast_Name = Request.Form("Last_Name")
fCity = Request.Form("City")
fZip = Request.Form("Zip")
fState = Request.Form("State")
fAddress = Request.Form("Address")


Dim conn, cmd, command, connection, logNumAffected

' SQL Command
command = "INSERT INTO table (First_Name, Last_Name, City, Zip, State, Address) VALUES ('"&fFirst_Name&"','"&fLast_Name&"','"&fCity&"','"&fZip&"','"&fAddress&"');"

' Create an ActiveX Data Object for the database connection
Set conn = Server.CreateObject("ADODB.Connection")

' specify the database connection details
connection = "Provider=SQLOLEDB;Server=servername;User ID=userid;Password=password;Database=databasename;"

' We need a command object to execute our SQL command
Set cmd = Server.CreateObject("ADODB.Command")

' Open the connection to the database
conn.open connection

' Tell the command object what SQL command to execute
cmd.commandText = command

' Tell the command object the active connection to the database
Set cmd.ActiveConnection = conn

' Execute the insert, and get the number of records affected (should be 1)
cmd.Execute logNumAffected,,adExecuteNoRecords

' Clean up open objects to save server memory
conn.close
set cmd=nothing
set conn=nothing
%>

0
 

Author Comment

by:delta179
ID: 18819374
I made the changes that you mentioned, but it is still not working. I know we were having this problem with a company web page. I am wondering if I need to have some kind of insert command in my code somewhere telling it to insert it to the database, because we have a connection, but how does it know to insert the information into the table?
Here is my changed code, but it still doesn't seem to be working.

<form action="--WEBBOT-SELF--" method="POST">
<!--webbot bot="SaveDatabase" SuggestedExt="asp" S-DataConnection="address" S-RecordSource="address" S-Form-Fields="First_Name Last_Name City Zip State Address" S-Form-DBFields="First_Name Last_Name City Zip State Address" -->First Name<input type="text"name"First_name" size="19" name="First_Name"/><br>
Last Name<input type="text" name="Last_Name" size="20"/><br>
Address<input type="text" name="Address" size="30"/><br>
City<input type="text" name="City" size="10"/><br>
State<input type="text" name="State" size="10"/><br>
Zip<input type="text" name="Zip" size="10"/><br>
&nbsp;
<input type="submit" name="bSubmit" value="Submit">
</form>
<form method="POST" action="--WEBBOT-SELF--">
      <!--webbot bot="SaveResults" U-File="_private/form_results.csv" S-Format="TEXT/CSV" S-Label-Fields="TRUE" -->
      <p>&nbsp;</p>
</form>
0
 
LVL 29

Expert Comment

by:rdivilbiss
ID: 18825063
>Here is my changed code, but it still doesn't seem to be working.

>how does it know to insert the information into the table?

Well it is supposed to work like this...You create the form in FrontPage, you tell FrontPage what database to use (database connection) and you map the fields on the form to the columns in the table in the database.  FP will create the ASP pages to perform the insert.

Your form is disconnected, so you'll need to reconnect it to a database connection and map the fields.

http://www.rodsdot.com/ee/fixFrontPageForm.asp

If you don't have FrontPage, or your web server does not have the SharePoint Server Extensions (formerly called FrontPage Server Extensions), then you will need to write the ASP code yourself as I showed above.
0

Join & Write a Comment

I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
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…

757 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

17 Experts available now in Live!

Get 1:1 Help Now