Solved

Form page and dump into my database

Posted on 2008-10-27
3
172 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
[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
  • 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

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
This article discusses how to create an extensible mechanism for linked drop downs.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
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)
Suggested Courses

623 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