Solved

Form page and dump into my database

Posted on 2008-10-27
3
168 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
The viewer will learn how to count occurrences of each item in an array.

808 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