You are on page 1of 20

What is ASP?

ASP is acronym for Active Server Page. It’s 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>
It’s now <%=Time()%>
</body>
</html>

Variables & Arrays


ASP variables are declared using VBScript declaration type. AssummingVbScript is
used, this is how you declare variable: DIM varaibleName or ConstvariableName. 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 Result Explanation

<% Jeep Grand Cherokee, This is simply illustration,


dim cars(3) Jeep Wrangler, Jeep NOT good example. If
cars(0)="Jeep Grand Cherokee" Liberty, Jeep Cherokee you writing items from
cars(1)="Jeep Wrangler"
cars(2)="Jeep Liberty"
an array, you would
cars(3)="Jeep Cherokee
probably write all the
Briarwood"
items at one time using
response.write(cars(0)&", ") Briarwood
loops instead of listing
response.write(cars(1)&", ")
response.write
response.write(cars(2)&", ")
statements.
response.write(cars(3))
%>
To write the array using for loop statement, do this.

Example Result Explanation

<%
dim cars(3)
dim x
cars(0)="Jeep Grand Cherokee"
cars(1)="Jeep Wrangler" Jeep Grand Cherokee
The variable x which
cars(2)="Jeep Liberty" Jeep Wrangler
starts from 0 to 3 acts as
cars(3)="Jeep Cherokee Jeep Liberty
an index for the array.
Briarwood" Jeep Cherokee Briarwood
for x= 0 to 3
response.write(cars(x)&"
")
next%>
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

<% Jeep This array has three cars


dim car1(3,2) Grand and each car has two
dim x,i Cheroke fields or columns. It's
car1(0,0)="Jeep Grand Cherokee" e 2002 like a table, row 0 has
car1(0,2)=2002 Jeep record of one car, row 1
car1(1,1)="Jeep Wrangler" Wrangle has record of another
car1(1,2)=2002 r 2002 car and so on We also
car1(2,1)="Jeep Liberty" Jeep define nested for loops.
car1(2,2)=2003 Liberty First one reads the row
car1(3,1)="Jeep Cherokee Briarwood" 2003 and second one reads
car1(3,2)=2003
for x=0 to 3
for i =0 to 2
response.write(car1(e,&a))
next
response.write("
"&" ") Jeep
next> Cheroke
ASP Sub Procedures e the column
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".

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

<%
Sub GetInfo()
dim name,telephone,fee This example simply declares, populates,
name="Mr. John Doe" & writes three variables in the asp sub
telephone="555-5555" procedure, 'GetInfo'. This sub is executed
fee=20 right after the end sub.
Response.write("Name: "& name
&"<br>") Here is the execution result:
Response.write("Telephone: "& telephone
&"<br>") Name: Mr. John Doe
Response.write("Fee: "& fee &"<br>") Telephone: 555-5555
End Sub Fee: 20
GetInfo()
%>

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:

<% Here is the execution result:


Sub circle(r)
dim pi,area,diameter,circum
pi=3.14
area=pi*r^2
diameter=2*r
circum=2*pi*r
The Circle with a radius of: 2 has the area
Response.write("The Circle with a radius
of: 12.56, the diameter of: 4 and a
of: "&r&" has the area of: "&area)
circumference of: 12.56
Response.write(", the diameter of:
"&diameter&" and a circumference of:
"&circum)
End Sub
%>
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 currProfitcurrProfit=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 Result:
equal to 1") N has the value
else equal to 1
response.write("N is not equal to
one")
end if
%>
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 This if statement will check if the
%> variablein_store is equal either 1 or 2 and
<%=fruit1%> is in store displays fruit1 or fruit2 according to the
<% true condition. <%=fruit1%> will display
else if in_store=2 then the value of the specified variable. It's
%> similar to response.write(fruit1).
<%=fruit2%> is in store Result: Apple is in store
<%
else
response.write("No value specified")
end if
%>

Sub Procedures 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 Result:
dat=WeekDay(Date) Today is Thursday
%> This example is to show the use of case
<% statement and there is better way to
Select Case dat show the day of the week in asp. The
case 1 variable dat is set to the day of the week
response.write("Today is Sunday") and it could have values from 1 to 7, 1 is
case 2 Sunday and 7 is Saturday. Case
response.write("Today is Monday") statement is used to display the day of
case 3 the week according to the value of
response.write("Today is Tuesday") variable dat.
case 4
response.write("Today is Wednesday")
case 5
response.write("Today is Thursday")
case 6
response.write("Today is Friday")
case 7
response.write("Today is Saturday")
end select
%>

If Statements 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.

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

<% Result:
Dim counter The counter is: 5
counter=0 The counter is: 4
for counter = 5 to 0 step -1 The counter is: 3
response.write("The counter is: The counter is: 2
"&counter&"<br>") The counter is: 1
next
The counter is: 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
Result:
counter=5
The counter is: 4
Do
The counter is: 3
response.write("The counter is:
The counter is: 2
"&counter&"<br>")
The counter is: 1
counter=counter-1
The counter is: 0
loop until counter =0
%>
You can also accomplish the loop this way:

<%
Dim counter
Result:
counter=5
The counter is: 4
Do Until counter=0
The counter is: 3
response.write("The counter is:
The counter is: 2
"&counter&"<br>")
The counter is: 1
counter=counter-1
The counter is: 0
loop
%>
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:
Day of the week: 5
"&WeekDay(Date))%>
<%response.write("Day of the month:
Day of the month: 18
"&Day(Date))%>
<%response.write("Current Year: "&Year(Date))%> Current Year: 2010
<%response.write("Current Year:
Current Year: 10
"&Right(Year(Date),2))%>
<%response.write("Today is:
Today is: Thursday
"&WeekDayName(WeekDay(Date)))%>
<%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

Top of Form
<form name=”userForm” method=”post”
action=”userForm.asp”> Enter a user name:
Enter a user name: <input type=”text”
name=”userName” size=”20”>
Enter a password: <input type=”password” Enter a password:
name=”password” size=”20”>
<inpute type=”submit” name=”submit” value=”Send”>
</form>
Send

Bottom of Form

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> Type something in the


<head> text boxes and hit submit
button to see the result
<title>Process form Info</title>
of this example. What
</head>
you will see is the result
<body>
of this code. The form
You have typed the user name <
will pass the information
%=Request.Form("userName")%> and the password <
to userForm.asp file,
%=Request.Form("password")%>.
which then will use the
</body>
power of Request to
</html>
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
form elements
Top of Form

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

Submit

Bottom of Form

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>
<title>Create txt file </title>
<body>
<%
Set
fileObj=Server.CreateObject("Scripting.Fil Set
eSystemObject") fileObj=Server.CreateObject("Scripting.Fil
set eSystemObject") creates the instance of
file1=fileObj.CreateTextFile("\asp\TextFile. the file object. set
txt") file1=fileObj.CreateTextFile("\asp\TextFile
file1.WriteLine("This is what goes to the .txt") creates the actual file, TextFile.txt
text file that would be created") within the specified path. WriteLine()
file1.WriteLine("This is the second line of writes the quoted line of text then we
the text file") close the file and set instance back to
file1.Close nothing.
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> Result
<body> Welcome
<% this is line one
Set this is line two
fileObj=Server.CreateObject("Scripting.FileSystemObject") this is line three
Set this is line four
listFile=fileObj.OpenTextFile(Server.MapPath("\cliktoprogram\ this is line five
asp\list.txt"), 1) This example displays
do while listFile.AtEndOfStream = false all the lines of the text
Response.Write(listFile.ReadLine) file one by one.
Response.Write("<br>")
loop
listFile.Close
Set listFile=Nothing
Set fileObj=Nothing
%>
</body>
</html>
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 Data Field


Name Type Size

Autonumb
user_id 8
er

Name Text 45

Commen
Text 200<>
ts

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 Result

<html> Top of Form

<head> Name:
<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) Commen
{ ts:
alert("Not enough comments entered");
return false;
}
else
{ Submit

return true;
} Bottom of Form
}
This form takes name and comments
//-->
and passes to save.asp file to be
</script> processed. Blank value will not pass to
</head> the save.asp file since we are preventing
<body> that using javascript. Enter some data
<form name="form" method="post" and hit the submit button.
action="save.asp"> Save the file as EnterData.html or
Name: <input type="text" name="name" EnterData.asp.
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.Opensql, 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
accommulateit 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.Opensql, 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.Opensql, 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.Opensql, 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.Opensql, Conn
Conn.Close
Set Rs=Nothing
Set Conn = Nothing
Response.Write "Successfully Updated"
End If
%>
</body>
</html>

You might also like