Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Form page and dump into my database

Posted on 2008-10-27
3
Medium Priority
?
176 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

876 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