You are on page 1of 20

What is ASP?

ASP is acronym for Active Server Page. Its Server side script language developed
by Microsoft. When ASP file is request by the browser, the browser does not send
the page back to the client browser instead its content is interpreted & processed by
the server. ASP is also script language that you combine with HTML document if your
server supports ASP. The default language is VBScript. However, you can specify to
use JavaScript or perlScript. If you are building E-commerce page, ASP is your ideal
language or one of the languages on your choice list.
Tools
In order to build ASP pages on your PC, first you need to install PWS [Microsoft
Personal Web Server] or IIS [Internet Information Server] for the internet. You can
download PWS from Microsoft web site: here . You can also learn how to set up here.
Otherwise you need host a that provides ASP server. see list of hosts.
Here is how to write hello world program in ASP:
<html>
<head>
<title>hello world program</title>
</head>
<body>
<% Response.write(Hello World) %>
</body>
</html>
This program declares a variable and writes it:
<html>
<body>
<%
dim h
h="Hello World"
response.write("Say: " & h)
%>
</body>
</html>
This program writes the current time:
<html>
<body>
Its now <%=Time()%>
</body>

</html>
Variables & Arrays
ASP variables are declared using VBScript declaration type. Assumming VbScript is
used, this is how you declare variable: DIM varaibleName or Const variableName. If
you want reject undeclared variables, use <% Option Explicit %> at the beginning
of your page. You would often see these two lines:
<%@ Language="Vbscript" %>
<% Option Explicit %>
at the beginning of ASP pages. First line sets the language and the second line
watches undeclared variables. VBScript and JavaScript variables are variant type
variable, which means they can take any type of values. Any variable name must
start with letter or underscore.
Watch this program to see how variables are used:
<%
Dim name, email, age
name=John M
email=you@you.com
age=356
response.write(Your Name: & name & "<br>")
response.write(Your Email: & email & "<br">)
response.Write(Your age: & age);
%>
The following is the result from the above example:
Your Name: Born Borner
Your Email: you@you.com
Your Age: 356
ASP Arrays
An array is an indexed list of things called elements or group of related variables.
For example, say that we want declare variables for list of cars like this; Dim car1,
car2, car2, car3,....
Here is how you would declare list of cars using array:
Dim cars(3); We simply declared array that takes 4 items. To assign values to this
array, do these:
cars(0)="Jeep Grand Cherokee"
cars(1)="Jeep Wrangler"
cars(2)="Jeep Liberty"
cars(3)="Jeep Cherokee Briarwood" Use this statement to write an item in the array:
response.write(cars(3)) This will write the 4th car on the list.
Here is the example we did in code

Example
<%
dim cars(3)
cars(0)="Jeep Grand Cherokee"
cars(1)="Jeep Wrangler"
cars(2)="Jeep Liberty"
cars(3)="Jeep Cherokee
Briarwood"
response.write(cars(0)&", ")
response.write(cars(1)&", ")
response.write(cars(2)&", ")
response.write(cars(3))
%>

Result

Explanation

Jeep Grand Cherokee,


Jeep Wrangler, Jeep
Liberty, Jeep Cherokee
Briarwood

This is simply illustration,


NOT good example. If
you writing items from
an array, you would
probably write all the
items at one time using
loops instead of listing
response.write
statements.

To write the array using for loop statement, do this.


Example

Result

<%
dim cars(3)
dim x
cars(0)="Jeep Grand Cherokee"
cars(1)="Jeep Wrangler"
cars(2)="Jeep Liberty"
cars(3)="Jeep Cherokee
Briarwood"
for x= 0 to 3
response.write(cars(x)&"
")
next%>

Jeep
Jeep
Jeep
Jeep

Explanation

Grand Cherokee
The variable x which
Wrangler
starts from 0 to 3 acts as
Liberty
an index for the array.
Cherokee Briarwood

Two dimensional Arrays


You can define two or more dimensional arrays by puting numbers withing the
parenthesis. Here is how you would define two dimensional array Dim cars(3,3).
The reason you may use this type of array is when you have records of each item.
For example, car, year, price,... and you want display one record at a time.
The following is an example of two dimensional array:
Example

Result Explanation

<%
dim car1(3,2)
dim x,i
car1(0,0)="Jeep Grand Cherokee"

Jeep
Grand
Cheroke
e 2002

This array has three cars


and each car has two
fields or columns. It's
like a table, row 0 has

car1(0,2)=2002
car1(1,1)="Jeep Wrangler"
car1(1,2)=2002
car1(2,1)="Jeep Liberty"
car1(2,2)=2003
car1(3,1)="Jeep Cherokee Briarwood"
car1(3,2)=2003
for x=0 to 3
for i =0 to 2
response.write(car1(e,&a))
next
response.write("
"&" ")
next>

Jeep
Wrangle
r 2002
Jeep
Liberty
2003
Jeep
Cheroke
ASP Sub Procedures
e
ASP Sub Procedures are a collection of ASP
Briarwo
statements that perform a task, and are executed od 2003
by an event procedure. Event Procedures are any
clickable objects, or onload event. Sub procedures
do not return a value, but executes it's content on
"call".

record of one car, row 1


has record of another car
and so on We also
define nested for loops.
First one reads the row
and second one reads
the column

This is an asp sub procedure that is used to write information stored in variables:

<%
Sub GetInfo()
dim name,telephone,fee
name="Mr. John Doe"
telephone="555-5555"
fee=20
Response.write("Name: "& name
&"<br>")
Response.write("Telephone: "& telephone
&"<br>")
Response.write("Fee: "& fee &"<br>")
End Sub
GetInfo()

This example simply declares, populates,


& writes three variables in the asp sub
procedure, 'GetInfo'. This sub is executed
right after the end sub.
Here is the execution result:
Name: Mr. John Doe
Telephone: 555-5555
Fee: 20

%>

You can pass an argument to the asp sub procedure, and provide the value(s) when
calling it.
This is an asp sub procedure that accepts an argument:

<%
Sub circle(r)
dim pi,area,diameter,circum
pi=3.14
area=pi*r^2
diameter=2*r
circum=2*pi*r
Response.write("The Circle with a radius
of: "&r&" has the area of: "&area)
Response.write(", the diameter of:
"&diameter&" and a circumference of:
"&circum)
End Sub
%>

Here is the execution result:


The Circle with a radius of: 2 has the area
of: 12.56, the diameter of: 4 and a
circumference of: 12.56

ASP Function Procedures


ASP Function Procedures are a series of VBscript statements enclosed by the
'Function', and 'End Function' statements. Function procedures are similar to a 'Sub
procedure', but can also return a value. An asp function procedure can accept
arguments (constants, variables, or expressions) that are passed to it by calling a
procedure).
This is a none-parameterized asp function procedure:
<%
function userName()
userName="MaryLou"
end function
%>

This function procedure remembers a username. You can use this function any
number of times in your program, and you can change it once to maintain it- use
'userName()' to call this function. For example: response.write("The username is:

"&userName())
This is a parameterized asp function procedure:
<%
Function total(price)
dim tax
tax=price*.09
total=price+tax
end Function
%>

The price value is provided when calling the function- Example: response.write("The
total price is: " & total(50))
This is an asp function procedure that accepts an argument:

<%
Function profit(sellPrice, cost)
dim pr
Here is the execution result:
profit=sellPrice-cost
End Function
Profit: $390
dim currProfit currProfit=profit(1280,890)
Response.write("Profit: $"&currProfit)
%>

ASP If Statements
Using if statement, ASP has the ability to make distinctions between different
possibilities. For example, you might have a script that checks if a variable consists
certain type of values.
Here is syntax for asp if statement.
<%
if condition is true then
do something
else
do something else
end if
%>

Check the following if statement that checks if a variable has a value equal to 1.
<%
dim n
n =1
if n= 1 then
response.write("N has the value
equal to 1")
else
response.write("N is not equal to
one")
end if
%>

Result:
N has the value
equal to 1

Nested If Statement
You would be able to check variety of conditions based on deversified values.
The following example is nested if statement to check two conditions:
<%
dim fruit1, fruit2, in_store
fruit1="Apple"
fruit2="Orange"
in_store=1
if in_store=1 then
%>
<%=fruit1%> is in store
<%
else if in_store=2 then
%>
<%=fruit2%> is in store
<%
else
response.write("No value specified")
end if
%>
Sub Procedures

This if statement will check if the variable


in_store is equal either 1 or 2 and
displays fruit1 or fruit2 according to the
true condition. <%=fruit1%> will display
the value of the specified variable. It's
similar to response.write(fruit1).
Result: Apple is in store

Case statement

ASP Case Statements


Case statement can be used instead of if statement suitably when one condition

could have multiple possibilities. Following example illustrates the use of case
statement
<% Dim dat
dat=WeekDay(Date)
%>
<%
Select Case dat
case 1
response.write("Today
case 2
response.write("Today
case 3
response.write("Today
case 4
response.write("Today
case 5
response.write("Today
case 6
response.write("Today
case 7
response.write("Today
end select
%>
If Statements

is Sunday")

Result:
Today is Thursday

This example is to show the use of case


statement and there is better way to
show the day of the week in asp. The
is Tuesday")
variable dat is set to the day of the week
and it could have values from 1 to 7, 1 is
is Wednesday") Sunday and 7 is Saturday. Case
statement is used to display the day of
is Thursday")
the week according to the value of
variable dat.
is Friday")
is Monday")

is Saturday")

Loops

ASP Loop Statements


Loops are set of instructions that repeat elements in specific number of times.
Counter variable is used to increment or decrement with each repetition of the loop.
The two major groups of loops are, For..Next and Do..Loop. While..Wend is another
type of Do..Loop. The For statements are best used when you want to perform a
loop in specific number of times. The Do and While statements are best used to
perform a loop an undetermined number of times.
This is a For..Next example which counts from 1 to 5.
<%
Dim counter
counter=0
for counter = 0 to 5
response.write("The counter is:
"&counter&"<br>")
next

Result:
The counter
The counter
The counter
The counter
The counter
The counter

is:
is:
is:
is:
is:
is:

0
1
2
3
4
5

%>
The above example increments a variable counter from 0 to 5 The values of counter
are incremented by 1 on each run before 6. We can modified how the values are
incremented by adding step # to the for counter statement.
Here is For..Next example incrementing values by two.
<%
Dim counter
counter=0
for counter = 0 to 5 step 2
response.write("The counter is:
"&counter&"<br>")
next
%>

Result:
The counter is: 0
The counter is: 2
The counter is: 4

The following example increments a variable counter from 5 to 0 The values are
decremented by 1. It's first example with reversed order.
<%
Dim counter
counter=0
for counter = 5 to 0 step -1
response.write("The counter is:
"&counter&"<br>")
next
%>

Result:
The counter
The counter
The counter
The counter
The counter
The counter

is:
is:
is:
is:
is:
is:

5
4
3
2
1
0

Do Loop
The Do..Loop structure repeats a block of statements until a specified condition is
met. There are three types of Do..Loops. Do..Until, Do..While, and While..Wend.
Do..While and While..Wend performs a loop statement as long as the condition
being tested is true while Do..Until performs a loop statement as long as the
condition tested is false. In both cases, you have a choice to perform the test at
start of the loop or at the end of the loop
This Do..Until loop example performs the test at the start of the loop:
<%
Dim counter
counter=5
Do
response.write("The counter is:
"&counter&"<br>")
counter=counter-1

Result:
The counter
The counter
The counter
The counter
The counter

is:
is:
is:
is:
is:

4
3
2
1
0

loop until counter =0


%>
You can also accomplish the loop this way:
<%
Dim counter
counter=5
Do Until counter=0
response.write("The counter is:
"&counter&"<br>")
counter=counter-1
loop
%>

Result:
The counter
The counter
The counter
The counter
The counter

is:
is:
is:
is:
is:

4
3
2
1
0

Displaying Date & Time with ASP


You use time() to get the current time, Date() to get the current date, and now() to
get the current date & time.
For example, these examples will Illustrate use of date and time functions.
Example

Result

<%=time()%>

11:41:44 PM

<%=date()%>

11/18/2010

<%=now()%>

11/18/2010 11:41:44 PM

<%response.write("Current date & time: "&now()) Current date & time: 11/18/2010
%>
11:41:44 PM
<%= FormatDateTime(Date, 0)%>

11/18/2010

<%= FormatDateTime(Date, 1)%>

Thursday, November 18, 2010

<%= FormatDateTime(now, 3)%>

11:41:44 PM

<%= FormatDateTime(now, 4)%>

23:41

<%response.write("Day of the week:


"&WeekDay(Date))%>

Day of the week: 5

<%response.write("Day of the month:


"&Day(Date))%>

Day of the month: 18

<%response.write("Current Year: "&Year(Date))%> Current Year: 2010


<%response.write("Current Year:

Current Year: 10

"&Right(Year(Date),2))%>
<%response.write("Today is:
"&WeekDayName(WeekDay(Date)))%>

Today is: Thursday

<%response.write("Hour Part: "&(hour(now)))%>

Hour part: 23

<%response.write("Minute Part: "&Minute(now()))


%>

Minute part: 41

<%response.write("Second Part: "&Second(now()))


Second part: 44
%>
Processing forms using ASP
You can process HTML forms using these two powerful ASP objects, Response and
Request. Response outputs the value to a page and Request retrieves values
from an object. Take a look at the following example:
Result
<form name=userForm method=post
action=userForm.asp>
Enter a user name: <input type=text
name=userName size=20>
Enter a user name:
Enter a password: <input type=password
name=password size=20>
<inpute type=submit name=submit value=Send> Enter a password:
</form>
Send

We just created HTML form and tell the browser to process the form using the file
"userForm.asp". The following is userForm.asp file that writes the values from the
form.
<html>
<head>
<title>Process form Info</title>
</head>
<body>
You have typed the user name <
%=Request.Form("userName")%> and the password <
%=Request.Form("password")%>.
</body>
</html>

Type something in the


text boxes and hit submit
button to see the result
of this example. What
you will see is the result
of this code. The form
will pass the information
to userForm.asp file,
which then will use the
power of Request to
write this information.

Form Processing Example 2


You can store value retrieved from form into variables in order to use these value
whatever way you want. Take a look these at this example which is little bit more
complex then previous one.
<html>
<head>
<title>Form Example 2</title>
</head>
<body>
<p><b>This example process basic form elements</b>
<form method="POST" action="formProcess.asp">
<p>Your name: <input type="text" name="Name" size="20"><br>
Status: <input type="radio" value="Customer" name="status">Customer <input
type="radio" name="status" value="Visitor">Visitor<br>
Do you own any of these trucks:<br>
<input type="checkbox" name="truck" value="Land Cruiser">Land Cruiser<br>
<input type="checkbox" name="truck" value="Sequoia">Sequoia<br>
<input TYPE="checkbox" name="truck" value="4Runner">4Runner<br>
<input TYPE="checkbox" name="truck" value="Highlander">Highlander<br>
<input TYPE="checkbox" name="truck" value="Tundra Access Cab">Tundra Access
Cab<br>
Car of Choice:<select size="1" name="product">
<option value="MR2 Spyder">MR2 Spyder</option>
<option value="Celica">Celica</option>
<option value="Matrix">Matrix</option>
<option value="Avalon">Avalon</option>
<option value="Camry">Camry</option>
<option value="Corolla">Corolla</option>
<option value="Echo">Echo</option>
<option value="Prius">Prius</option>
<option value="RAV4 EV">RAV4 EV</option>
</select><br>
Enter some general comments about what you think about Toyota cars:<br>
<textarea rows="5" name="Comments" cols="50"></textarea><br>
<align="center"><input type="submit" value="Submit" name="submit"><br>
</form>
</body>
</html>
Result of the above code
This example process basic

Code for formProcess.asp


<html>
<head>

form elements
<title>Result of your information</title>
</head>
Status:
Customer
Visitor <body>
Do you own any of these trucks:
<%
dim name, status, truck, car, comments
Land Cruiser
name=Request.Form("Name")
Sequoia
status=Request.Form("status")
car=Request.Form("car")
4Runner
comments=Request.Form("comments")
truck=Request.Form("truck")
Highlander
%>
Tundra Access Cab
Your name: <b><%=name%></b><br>
Status: <b><%=status%></b><br>
Car of Choice:
Your favourite car is: <b><%=car%></b><br>
Any comments about Toyota cars:
You currently own these trucks:<b> <%=truck
%></b><br>
Your comments about Toyota products:<b><
%=comments%></b>
</body>
Your name:

Submit

Writing to a Text File using ASP


You can write to or read from a text file using ASP. The following is simple example
that illustrates how to create text file and write some information to it.
<html>
Set
<title>Create txt file </title>
fileObj=Server.CreateObject("Scripting.Fil
<body>
eSystemObject") creates the instance of
<%
the file object. set
Set
file1=fileObj.CreateTextFile("\asp\TextFile
fileObj=Server.CreateObject("Scripting.File .txt") creates the actual file, TextFile.txt
SystemObject")
within the specified path. WriteLine()
set
writes the quoted line of text then we
file1=fileObj.CreateTextFile("\asp\TextFile.t close the file and set instance back to
xt")
nothing.
file1.WriteLine("This is what goes to the
text file that would be created")
file1.WriteLine("This is the second line of
the text file")
file1.Close

set file1=nothing
set fileObj=nothing
%>
</body>
</html>
Reading from a Text File
Reading from a text file is also very easy and similar to writing to it. The following
example illustrates how to read from a text file.
<html>
<body>
<%
Set
fileObj=Server.CreateObject("Scripting.FileSystemObject")
Set
listFile=fileObj.OpenTextFile(Server.MapPath("\cliktoprogram\
asp\list.txt"), 1)
do while listFile.AtEndOfStream = false
Response.Write(listFile.ReadLine)
Response.Write("<br>")
loop
listFile.Close
Set listFile=Nothing
Set fileObj=Nothing
%>
</body>
</html>

Result
Welcome
this is line
this is line
this is line
this is line
this is line

one
two
three
four
five

This example displays


all the lines of the text
file one by one.

To display all the lines at once without line breaks, simply replace the lines starting
with do while and ending with loop to Response.Write(listFile.ReadAll).

To display the first line of the text file use, Response.Write(listFile.ReadLine).

To skip line of a text file use,listFile.SkipLine

To skip part of line of a text use,listFile.Skip(2). This will skip 2 characters.

To write an empty line use, WriteBlankLines

Also you can assign the line to a variable like this,text=listFile.ReadLine

Adding Data to Access Database

To add data to a database table, you need an existing database plus the table to
add the data to. Let us assume that you have Access Database file name
FeedBack.mdb in the same folder as this file with the following table:
tblFeeds
Field
Name

Data
Type

Field
Size

user_id

Autonumb
8
er

Name

Text

Commen
Text
ts

45
200<>

To add a data to the table tblFeeds, first we will have to create a form to enter the
data and then open the database and make the connection.
Here is the form to enter the data before adding to the database:
Form Example
<html>
<head>
<title> Adding to database example </title>
<script type="text/javascript">
<!-function validate()
{
if(document.form.name.value=="")
{
alert("Name is missing");
return false;
}
if(document.form.comments.value.length<8)
{
alert("Not enough comments entered");
return false;
}
else
{
return true;
}
}
//-->

Result
Name:

Commen
ts:

Submit

This form takes name and comments and


passes to save.asp file to be processed.
Blank value will not pass to the save.asp
file since we are preventing that using
javascript. Enter some data and hit the
submit button.
Save the file as EnterData.html or
EnterData.asp.

</script>
</head>
<body>
<form name="form" method="post"
action="save.asp">
Name: <input type="text" name="name"
maxlength="45"> <br>
Comments: <textarea cols="20" rows="8"
name="comments"
maxlength="200"> </textarea><br>
<input type="submit" name="Save"
value="Submit" onClick="return validate();">
</form>
</body>
</html>

Now, you insert the new record to the database using the information provided through
EnterData.asp. Here is the code to do this:
save.asp
<%
Dim Conn
Dim Rs
Dim sql
'Create an ADO connection and recordset object
Set Conn = Server.CreateObject("ADODB.Connection")
Set Rs = Server.CreateObject("ADODB.Recordset")
'Set an active connection and select fields from the database
Conn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" &
Server.MapPath("FeedBack.mdb")
sql= "SELECT name, comments FROM tblFeeds;"
'Set the lock and cursor type
Rs.CursorType = 2
Rs.LockType = 3
Rs.Open sql, Conn

'Open the recordset with sql query

Rs.AddNew 'Prepare the database to add a new record and add


Rs.Fields("name") = Request.Form("name")
Rs.Fields("comments") = Request.Form("comments")

Rs.Update 'Save the update


Rs.Close
Set Rs = Nothing
Set Conn = Nothing
%>
The third field (user_no) of our table is auto generated and sequentially will
accommulate it self on each addition of new record.
You redirect the user to another page when the record is added to the database
using
<%response.redirect("view.asp")%>

After the data is added to the database, the next thing you may want do is view to see what is
added. The code is very similar.
This code bellow displays the fields.
view.asp
<%
Dim Conn
Dim Rs
Dim sql
Set Conn = Server.CreateObject("ADODB.Connection")
Set Rs = Server.CreateObject("ADODB.Recordset")
Conn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" &
Server.MapPath("FeedBack.mdb")
sql= "SELECT name, comments FROM tblFeeds;"
Rs.Open sql, Conn
Do While not Rs.EOF
Response.Write
("============================================="&"<br
>")
Response.Write ("Name: " & "<font color='red'>" & Rs("name") & "</font>")
Response.Write ("<br>")
Response.Write ("Comment: " & "<font color='red'>" & Rs("comments") &
"</font>")
Response.Write ("<br>")
Rs.MoveNext
Loop
Rs.Close
Set Rs = Nothing
Set Conn = Nothing
%>

View this file

Update a record
There are more than one way to do things. For this example, we are going to list
items from the database so that you can select a record using radio button.
Code to list records from tblFeeds
<html>
<body >
Select name to update.
<%
Dim Conn, Rs, sql
Set Conn = Server.CreateObject("ADODB.Connection")
Set Rs = Server.CreateObject("ADODB.Recordset")
Conn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" &
Server.MapPath("FeedBack.mdb")
sql= "SELECT * FROM tblFeeds;"
Rs.Open sql, Conn
Response.Write "<FORM name='Update' method='post' action='toUpdateT.asp'>"
Response.Write "<table border=1 cellspacing=0>"
Response.Write "<tr>"&"<td colspan='3' align='center'>"&"Select a comment to
update and click select"&"</td>"&"</tr>"
Response.Write "<tr>"&"<th align='center' colspan='2'>"&"Name"&"</th>"&"<th
align='center'>"&"Comment"&"</th>"&"</tr>"
if NOT Rs.EOF then
Do While not Rs.EOF
Response.Write ("<tr>")
Response.Write ("<td>"&"<input type='radio' name='ID'
value="&Rs("user_id")&">"&"</td>")
Response.Write ("<td>"&Rs("name")&"</td>")
Response.Write ("<td>"&Rs("comments")&"</td>")
Response.Write ("</tr>")
Rs.MoveNext
Loop
else
Response.Write("No records found")
end if
Response.Write("<tr>"&"<td colspan='3' align='center'>"&"<input type ='submit'
name='submit' value='Select' >"&"</td>"&"</tr>")
Response.Write "</table>"
Rs.Close
Set Rs = Nothing
Set Conn = Nothing
%>
</form>

</body>
</html>
Click here for result
User_ID is a unique field which identifies the selected record. When the user
selects record and clicks on Select, the information is processed in the toUpdatT.asp
file.
toUpdateT.asp file allows the user edit the record
<html>
<body>
<form name="updated" action="updateComment.asp" method="post">
<%
Dim ID, name, comments
ID= Request.Form("ID")
name = Request.Form("name")
comments=Request.Form("comments")
if name="" then
Response.Write "You did not select a name to update!"
Else
Dim Conn, Rs, sql
Set Conn = Server.CreateObject("ADODB.Connection")
Set Rs = Server.CreateObject("ADODB.Recordset")
Conn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" &
Server.MapPath("FeedBack.mdb")
sql= "Select * FROM tblFeeds WHERE user_id="&ID
Rs.Open sql, Conn
if NOT Rs.EOF then
%>
<table border=1 cellspacing=0>
<tr><td colspan="2" align="center">Update and save</td></tr>
<tr>
<td>Name: </td>
<td><input type="text" name="name" size="30" maxlength="45" value="<
%=Rs("name")%>"></td>
</tr><tr>
<td>Comment: </td>
<td><input type="text" name="comments" size="30" maxlength="250"
value="<%=Rs("comments")%>"></td>
</tr><tr>
<td colspan="2" align="center"><input type="submit" name="submit"
value="Save"></td>
</tr>
</table>

</form>
<%
else
Response.Write("Record does not exist")
end if
Conn.Close
Set Conn = Nothing
End If
%>
</body>
</html>
After the new data is entered, the next thing is to save the data and the following
is the file to do that.
updateComment.asp saves the new information
<html>
<body>
<%
Dim name,comments, user_id
ID = Request.Form("ID")
name = Request.Form("name")
comments=Request.Form("comments")
if name="" OR comments="" then
Response.Write "A field was left empty, please try again!"
Else
Dim Conn ,Rs, sql
Set Conn = Server.CreateObject("ADODB.Connection")
Set Rs = Server.CreateObject("ADODB.Recordset")
Conn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" &
Server.MapPath("FeedBack.mdb")
sql= "Update tblFeeds Set name='"& name & "', comments='" & comments &"'
WHERE user_id=" & ID
Rs.Open sql, Conn
Conn.Close
Set Rs=Nothing
Set Conn = Nothing
Response.Write "Successfully Updated"
End If
%>
</body>
</html>

You might also like