?
Solved

database connection

Posted on 2007-03-29
6
Medium Priority
?
200 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
[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
  • 3
6 Comments
 
LVL 29

Accepted Solution

by:
rdivilbiss earned 2000 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

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
The viewer will learn how to count occurrences of each item in an array.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Suggested Courses

752 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