Solved

Form page and dump into my database

Posted on 2008-10-27
3
167 Views
Last Modified: 2010-05-18
I have SQL Server Express.  I am making a webpage with fields on it such as Name and Address.  I want to take this information and dump it into my SQL Server Express database.  Can someone give me some direction on how to start doing this.  Better yet, do you have any code examples of a very basic webpage that already does this??

0
Comment
Question by:al4629740
  • 2
3 Comments
 
LVL 10

Expert Comment

by:KenAdney
ID: 22814628
There's several ways to do this.  Here's a somewhat abbreviated example in classic ASP:

<%
IF request.form("datecomplete") <> "" THEN
Set DataConn = Server.CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.Recordset")
DataConn.Open "Provider=sqloledb;" & _
                  "Data Source=the_server;" & _
                  "Initial Catalog=your_database;" & _
                 "User Id=database_user_ID;" & _
                "Password=database_user_password;"
sql = "SELECT * FROM your_table"
rs.Open sql, DataConn, 1, 3
rs.AddNew
rs.Fields("address")    = request.form("address")
rs.Update
DataConn.Close
Set DataConn = Nothing
Set rs = Nothing
%>
<form action="my_form.asp" method="post">
<p>What's your address? <text name="address"></text></p>
<input type="hidden" name="datecomplete" value='<%= now %>'>
<input type="submit" name="submit" value="Submit this form">
</form>       
0
 

Author Comment

by:al4629740
ID: 22843011
I placed the code in Notepad and saved it as temp.asp

where would I enter the address?  Is there a text box?
0
 
LVL 10

Accepted Solution

by:
KenAdney earned 500 total points
ID: 22843623
The bottom 5 lines of that code is the form where you'd enter the address.

In short, you have a standard html form with one hidden field (in this case, called datecomplete) and the form "posts" to itself (the same page).  There's an IF...THEN at the top that says if datecomplete has a value then add everything to the database (because your user must have filled everything out and submitted it) but if the datecomplete is blank (as would be the case when the page first loads) then display the html form.

The hard part is that this is server side code, so it has to be on a server (that supports ASP) to display properly.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

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

20 Experts available now in Live!

Get 1:1 Help Now