Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

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

database connection

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
delta179
Asked:
delta179
  • 3
1 Solution
 
rdivilbissCommented:
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
 
rdivilbissCommented:
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
 
delta179Author Commented:
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
 
rdivilbissCommented:
>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

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

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