iNET Interactive - Online Advertising Agency
          
   Home    Authors    About    Login    Contact Us
   Search:   
Advanced Search     
  Articles

  ASP (26)
  ASP.NET (19)
  C and C++ (4)
  CFML (2)
  CGI and Perl (16)
  Flash (2)
  Java (7)
  JavaScript (28)
  PHP (92)
  MySQL (13)
  MSSQL (3)
  HTML (35)
  SEO (9)
  Visual Basic (12)
  CSS (13)
  SSI (5)
  XML (12)
  C# (14)

  Developer News

July 3, 2008
Poll: Which Web editor do you use?
About
 
July 3, 2008
Book Review: Head First JavaScript
WebReference.com
 
July 3, 2008
10 Things You Can Do With a Wiki
About
 
July 2, 2008
Web Host Reviews - 10 New Reviews
About
 
July 2, 2008
14 Reasons You Should Join a Social Network
About
 
July 1, 2008
Mark Boulton's Freelance Design Secrets
SitePoint
 
Courtesy of moreover.com
 
Want to receive new articles via e-mail? Click here!
/Home /ASP

Step by step guide to a Database-Driven application 

  Views:    20503
  Votes:    11
by Romeo Marquez 12/13/03 Rating: 

Synopsis:

Here’s a four step tutorial about an application that can collect data, store it in a DB, modify it and delete it.
Pages: firstback1 3 4 forwardlast
The Article

PART II :  Storing the Data
We’ll begin by adding an HTML form to listing.asp (previously created in Part I)

Here’s the code:

 

<% Option Explicit %>

<!-- #INCLUDE FILE="DBInfo.asp" -->

<HTML>

<HEAD><TITLE>Users listing</TITLE></HEAD>

<BODY>

<%

Dim objRS

Set objRS = Server.CreateObject ("ADODB.Recordset")

objRS.Open "Users", strConnect, adOpenForwardOnly, adLockReadOnly, adCmdTable

response.write  "<table width='400' border='0' cellpadding='2'>

 <tr bgcolor='#CCD6E0'><td><b>User ID</b></td>" & _

"<td><b>Full Name</b></td><td><b>Email</b></td></tr>"

While Not objRS.EOF

            Response.Write "<tr><td>"

            Response.Write objRS("ID") & "</td><td>" &objRS("Name") & " "&objRS("Lastname")& _

                                                          "</td><td>"&objRS("Email")&"</td></tr>"

            objRS.MoveNext

Wend

response.write "</table>"

objRS.Close                   

Set objRS = Nothing          

%>

<!-- We add a form to collect data and send it to addnew.asp  -->

<br><form action="addnew.asp" method="post"> 

<table cellspacing="2" cellpadding="2" border="0">

<tr>

    <td align="right">Name:</td>

    <td align="left"><input type="Text" name="name"></td>

</tr><tr>

    <td align="right">Last name:</td>

    <td align="left"><input type="Text" name="lastname"></td>

</tr><tr>

    <td align="right">Email:</td>

    <td align="left"><input type="Text" name="email"></td>

</tr><tr>

    <td align="right">Password:</td>

    <td align="left"><input type="Text" name="password"></td>

</tr><tr>

    <td align="right"></td>

    <td align="left"><input type="Submit" value="Submit"></td>

</tr></table>

</form>

</BODY></HTML>

 

For now we won’t worry about data validation.

We’ll do that later as I do not want to make these first examples any more difficult.

 

Now, we’ll use the recordset method ADDNEW, which allows us to add a new record to any table in a database.

Here’s the code for addnew.asp

 

<% Option Explicit %>

<!-- #INCLUDE FILE="DBInfo.asp" -->

<%

  Dim objRS

  Set objRS = Server.CreateObject ("ADODB.Recordset")

  objRS.Open "users", strConnect, adOpenStatic, adLockOptimistic, adCmdTable

  ‘ The previous line opens the DB with write permission.

 

  objRS.AddNew ‘ This allows to update the table, then we provide the values.

  objRS("name") = request.form("name")

  objRS("lastname") = request.form("lastname")

  objRS("email") = request.form("email")

  objRS("password") = request.form("password")

  objRS.Update   ‘ This will commit and save the data to the DB

  objRS.Close

 

  Set objRS = Nothing

  response.redirect "listing.asp"

%>

 

So, as you can see, it’s pretty easy to add new records to the Data Base using the AddNew and Update methods.

 

On Part III you’ll learn to modify existing records.

Pages: firstback1 3 4 forwardlast

Similar/related articles:


 
  Sponsors