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 20, 2008
Wiki: A Solution to the Web Design Problem
About
 
July 19, 2008
Top 10 Social Networking Sites
About
 
July 19, 2008
Plurk or Twitter: Which one is Better?
About
 
July 19, 2008
Create Menus with Lists and CSS
About
 
July 17, 2008
Poll: What do you do when you can't design?
About
 
July 17, 2008
22 Reasons to Plurk
About
 
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:    20791
  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 2 4 forwardlast
The Article

PART III : Modifying Records

We’ll need to do some changes in listing.asp, create edit.asp and create saveEdit.asp

 

First we'll start by adding a column to our table in listing.asp

Here’s just the new code for that table, replace this in listing.asp:

 

<%

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><td><b>Edit</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><td><a href='edit.asp?id="&objRS("id")&"'>Edit</a></td></tr>"

            objRS.MoveNext

Wend

response.write "</table>"

objRS.Close                   

Set objRS = Nothing          

%>

 

We’ll use the ID to pass it as a parameter in the link, that way; edit.asp will know what record will be modified.

 

Here’s the code for edit.asp

<% Option Explicit %>

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

<%

  Dim objRS, strQuery

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

  strQuery= "select * from USERS where id="&request.querystring("id")

  objRS.Open strQuery, strConnect, adOpenForwardOnly, adLockReadOnly, adCmdText

%>

<html><head><title>Editing existing records</title></head>

<body>Editing record: <%= objRS("id") %>

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

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

<tr><td align="right">ID:</td>

<td align="left"><%= objRS("id") %><input type="hidden" name="id" value="<%= objRS("id") %>"></td></tr>

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

<td align="left"><input type="Text" name="name" value="<%= objRS("name") %>"></td></tr>

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

<td align="left"><input type="Text" name="lastname" value="<%= objRS("lastname") %>"></td></tr>

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

<td align="left"><input type="Text" name="email" value="<%= objRS("email") %>"></td></tr>

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

<td align="left"><input type="Text" name="password" value="<%= objRS("password") %>"></td></tr>

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

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

</tr></table></form>

</body></html>

 

With the previous code, we displayed an HTML Form filled with the data retrieved from the DB.

This will allow showing what is currently stored and the user can modify only what he/she needs.

 

Now, for the final part, save the following code to saveEdit.asp

 

<% Option Explicit %>

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

<%

  Dim objRS, id,strQuery

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

  strQuery= "select * from USERS where id="&request.form("id")

  objRS.Open strQuery, strConnect, adOpenStatic, adLockOptimistic, adCmdText

  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"

%>

 

With these 3 steps, we can edit any existing record in our database and save those changes.

In the following page, we’ll learn to delete existing records.

Pages: firstback1 2 4 forwardlast

Similar/related articles:


 
  Sponsors