You are on page 1of 19

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 bac!
to the client browser instead its content is interpreted " processed by the server. ASP is also
script language that you combine with #$M% document if your server supports ASP. $he default
language is &'Script. #owever you can specify to use (avaScript or perlScript. If you are
building )*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 P+ first you need to install PWS ,Microsoft Personal Web
Server- or IIS ,Internet Information Server- for the internet. .ou can download PWS from
Microsoft web site/ here . .ou can also learn how to set up here.
0therwise you need host a that provides ASP server. see list of hosts.
#ere is how to write hello world program in ASP/
1html2
1head2
1title2hello world program13title2
13head2
1body2
14 5esponse.write67#ello World89 42
13body2
13html2
$his program declares a variable and writes it/
1html2
1body2
14
dim h
h:;#ello World;
response.write6;Say/ ; " h9
42
13body2
13html2
$his program writes the current time/
1html2
1body2
Its now 14:$ime6942
13body2
13html2
&ariables " Arrays
ASP variables are declared using &'Script declaration type. Assumming &bScript is used this
is how you declare variable/ <IM varaible=ame or +onst variable=ame. If you want re>ect
undeclared variables use 14 0ption )?plicit 42 at the beginning of your page. .ou would
often see these two lines/
14@ %anguage:;&bscript; 42
14 0ption )?plicit 42
at the beginning of ASP pages. Airst line sets the language and the second line watches
undeclared variables. &'Script and (avaScript variables are variant type variable which means
they can ta!e any type of values. Any variable name must start with letter or underscore.
Watch this program to see how variables are used/
14
<im name email age
name:8(ohn M8
email:8you@you.com8
age:BCD
response.write67.our =ame/ 7 " name " ;1br2;9
response.write67.our )mail/ 7 " email " ;1br;29
response.Write67.our age/ 7 " age9E
42
$he following is the result from the above e?ample/
.our =ame/ 'orn 'orner
.our )mail/ you@you.com
.our Age/ BCD
ASP Arrays
An array is an inde?ed list of things called elements or group of related variables. Aor e?ample
say that we want declare variables for list of cars li!e thisE <im carF carG carG carB....
#ere is how you would declare list of cars using array/
<im cars6B9E We simply declared array that ta!es H items. $o assign values to this array do
these/
cars6I9:;(eep Jrand +hero!ee;
cars6F9:;(eep Wrangler;
cars6G9:;(eep %iberty;
cars6B9:;(eep +hero!ee 'riarwood; Kse this statement to write an item in the array/
response.write6cars6B99 $his will write the Hth car on the list.
#ere is the e?ample we did in code
Example Result Explanation
14
dim cars6B9
cars6I9:;(eep Jrand +hero!ee;
cars6F9:;(eep Wrangler;
(eep Jrand +hero!ee (eep
Wrangler (eep %iberty
(eep +hero!ee 'riarwood
$his is simply illustration
=0$ good e?ample. If you
writing items from an array
you would probably write all
cars6G9:;(eep %iberty;
cars6B9:;(eep +hero!ee 'riarwood;
response.write6cars6I9"; ;9
response.write6cars6F9"; ;9
response.write6cars6G9"; ;9
response.write6cars6B99
42
the items at one time using
loops instead of listing
response.write statements.
$o write the array using for loop statement do this.
Example Result Explanation
14
dim cars6B9
dim ?
cars6I9:;(eep Jrand +hero!ee;
cars6F9:;(eep Wrangler;
cars6G9:;(eep %iberty;
cars6B9:;(eep +hero!ee 'riarwood;
for ?: I to B
response.write6cars6?9";
;9
ne?t42
(eep Jrand +hero!ee
(eep Wrangler
(eep %iberty
(eep +hero!ee 'riarwood
$he variable ? which starts
from I to B acts as an inde?
for the array.
Two dimensional Arrays
.ou can define two or more dimensional arrays by puting numbers withing the parenthesis.
#ere is how you would define two dimensional array <im cars6BB9. $he reason you may use
this type of array is when you have records of each item. Aor e?ample car year price... and
you want display one record at a time.
$he following is an e?ample of two dimensional array/
Example Result Explanation
14
dim carF6BG9
dim ?i
carF6II9:;(eep Jrand +hero!ee;
carF6IG9:GIIG
carF6FF9:;(eep Wrangler;
carF6FG9:GIIG
carF6GF9:;(eep %iberty;
carF6GG9:GIIB
carF6BF9:;(eep +hero!ee 'riarwood;
carF6BG9:GIIB
for ?:I to B
(eep
Jrand
+hero!ee
GIIG
(eep
Wrangler
GIIG
(eep
%iberty
GIIB
(eep
+hero!ee
$his array has three cars
and each car has two fields
or columns. ItLs li!e a table
row I has record of one car
row F has record of another
car and so on We also
define nested for loops.
Airst one reads the row and
second one reads the
column
for i :I to G
response.write6carF6e"a99
ne?t
response.write6;
;"; ;9
ne?t2
ASP Sub Procedures
ASP Sub Procedures are a collection of ASP
statements that perform a tas! and are e?ecuted by an
event procedure. )vent Procedures are any clic!able
ob>ects or onload event. Sub procedures do not return a
value but e?ecutes itLs content on ;call;.
'riarwoo
d GIIB
$his is an asp sub procedure that is used to write information stored in variables/

14
Sub JetInfo69
dim nametelephonefee
name:;Mr. (ohn <oe;
telephone:;CCC*CCCC;
fee:GI
5esponse.write6;=ame/ ;" name ";1br2;9
5esponse.write6;$elephone/ ;" telephone
";1br2;9
5esponse.write6;Aee/ ;" fee ";1br2;9
)nd Sub
JetInfo69
42
$his e?ample simply declares populates "
writes three variables in the asp sub procedure
LJetInfoL. $his sub is e?ecuted right after the end
sub.

#ere is the e?ecution result/

=ame/ Mr. (ohn <oe
$elephone/ CCC*CCCC
Aee/ GI

.ou can pass an argument to the asp sub procedure and provide the value6s9 when calling it.
$his is an asp sub procedure that accepts an argument/

14
Sub circle6r9
dim piareadiametercircum
pi:B.FH
#ere is the e?ecution result/

$he +ircle with a radius of/ G has the area of/
FG.CD the diameter of/ H and a circumference
area:piMrNG
diameter:GMr
circum:GMpiMr
5esponse.write6;$he +ircle with a radius of/
;"r"; has the area of/ ;"area9
5esponse.write6; the diameter of/ ;"diameter";
and a circumference of/ ;"circum9
)nd Sub
42
of/ FG.CD
ASP Function Procedures
ASP Aunction Procedures are a series of VBscript statements enclosed by the LAunctionL and
L)nd AunctionL statements. Aunction procedures are similar to a LSub procedureL but can also
return a value. An asp function procedure can accept arguments 6constants variables or
e?pressions9 that are passed to it by calling a procedure9.

$his is a none-parameterized asp function procedure/

14
function user=ame69
user=ame:;Mary%ou;
end function
42

$his function procedure remembers a username. .ou can use this function any number of times
in your program and you can change it once to maintain it* use Luser=ame69L to call this
function. Aor e?ample/ response.write6;$he username is/ ;"user=ame699

$his is a parameterized asp function procedure/

14
Aunction total6price9
dim ta?
ta?:priceM.IO
total:pricePta?
end Aunction
42

$he price value is provided when calling the function* )?ample/ response.write6;$he total price
is/ ; " total6CI99
$his is an asp function procedure that accepts an argument/

14
Aunction profit6sellPrice cost9
dim pr
profit:sellPrice*cost
)nd Aunction
dim currProfit currProfit:profit6FGQIQOI9
5esponse.write6;Profit/ R;"currProfit9
42
#ere is the e?ecution result/

Profit/ RBOI
ASP ! Statements
Ksing if statement ASP has the ability to ma!e distinctions between different possibilities. Aor
e?ample you might have a script that chec!s if a variable consists certain type of values.
#ere is synta? for asp if statement.
14
if condition is true then
do something
else
do something else
end if
42
+hec! the following if statement that chec!s if a variable has a value equal to F.
14
dim n
n :F
if n: F then
response.write6;= has the value equal to
F;9
else
response.write6;= is not equal to one;9
end if
42
5esult/
= has the value equal
to F
"ested ! Statement
.ou would be able to chec! variety of conditions based on deversified values.
$he following e?ample is nested if statement to chec! two conditions/
14
dim fruitF fruitG inSstore
$his if statement will chec! if the variable
in_store is equal either F or G and displays
fruitF:;Apple;
fruitG:;0range;
inSstore:F
if inSstore:F then
42
14:fruitF42 is in store
14
else if inSstore:G then
42
14:fruitG42 is in store
14
else
response.write6;=o value specified;9
end if
42
fruitF or fruitG according to the true condition. <
%=fruit1%> will display the value of the
specified variable. ItLs similar to
response.write(fruit1).
5esult/ Apple is in store
Sub Procedures +ase statement
ASP #ase Statements
+ase statement can be used instead of if statement suitably when one condition could have
multiple possibilities. Aollowing e?ample illustrates the use of case statement
14 <im dat
dat:Wee!<ay6<ate9
42
14
Select +ase dat
case F
response.write6;$oday is Sunday;9
case G
response.write6;$oday is Monday;9
case B
response.write6;$oday is $uesday;9
case H
response.write6;$oday is Wednesday;9
case C
response.write6;$oday is $hursday;9
case D
response.write6;$oday is Ariday;9
case T
response.write6;$oday is Saturday;9
5esult/
$oday is $hursday
$his e?ample is to show the use of case
statement and there is better way to show the
day of the wee! in asp. $he variable dat is set
to the day of the wee! and it could have values
from F to T F is Sunday and T is Saturday.
+ase statement is used to display the day of
the wee! according to the value of variable dat.
end select
42
If Statements %oops
ASP $oop Statements
%oops are set of instructions that repeat elements in specific number of times. +ounter variable
is used to increment or decrement with each repetition of the loop. $he two ma>or groups of
loops are Aor..=e?t and <o..%oop. While..Wend is another type of <o..%oop. $he Aor
statements are best used when you want to perform a loop in specific number of times. $he <o
and While statements are best used to perform a loop an undetermined number of times.
$his is a Aor..=e?t e?ample which counts from F to C.
14
<im counter
counter:I
for counter : I to C
response.write6;$he counter is/
;"counter";1br2;9
ne?t
42
5esult/
$he counter is/ I
$he counter is/ F
$he counter is/ G
$he counter is/ B
$he counter is/ H
$he counter is/ C
$he above e?ample increments a variable counter from I to C $he values of counter are
incremented by F on each run before D. We can modified how the values are incremented by
adding step U to the for counter statement.
#ere is Aor..=e?t e?ample incrementing values by two.
14
<im counter
counter:I
for counter : I to C step G
response.write6;$he counter is/
;"counter";1br2;9
ne?t
42
5esult/
$he counter is/ I
$he counter is/ G
$he counter is/ H
$he following e?ample increments a variable counter from C to I $he values are decremented
by F. ItLs first e?ample with reversed order.
14
<im counter
counter:I
for counter : C to I step *F
response.write6;$he counter is/
;"counter";1br2;9
5esult/
$he counter is/ C
$he counter is/ H
$he counter is/ B
$he counter is/ G
$he counter is/ F
ne?t
42
$he counter is/ I
%o $oop
$he <o..%oop structure repeats a bloc! of statements until a specified condition is met. $here
are three types of <o..%oops. <o..Kntil <o..While and While..Wend. <o..While and
While..Wend performs a loop statement as long as the condition being tested is true while
<o..Kntil 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
$his <o..Kntil loop e?ample performs the test at the start of the loop/
14
<im counter
counter:C
<o
response.write6;$he counter is/
;"counter";1br2;9
counter:counter*F
loop until counter :I
42
5esult/
$he counter is/ H
$he counter is/ B
$he counter is/ G
$he counter is/ F
$he counter is/ I
.ou can also accomplish the loop this way/
14
<im counter
counter:C
<o Kntil counter:I
response.write6;$he counter is/
;"counter";1br2;9
counter:counter*F
loop
42
5esult/
$he counter is/ H
$he counter is/ B
$he counter is/ G
$he counter is/ F
$he counter is/ I
%isplayin& %ate ' Time with ASP
.ou use time() to get the current time Date() to get the current date and now() to get the
current date " time.
Aor e?ample these e?amples will Illustrate use of date and time functions.
Example Result
14:time6942 FF/HF/HH PM
14:date6942 FF3FQ3GIFI
14:now6942 FF3FQ3GIFI FF/HF/HH PM
14response.write6;+urrent date " time/ ;"now69942
+urrent date " time/ FF3FQ3GIFI
FF/HF/HH PM
14: Aormat<ate$ime6<ate I942 FF3FQ3GIFI
14: Aormat<ate$ime6<ate F942 $hursday =ovember FQ GIFI
14: Aormat<ate$ime6now B942 FF/HF/HH PM
14: Aormat<ate$ime6now H942 GB/HF
14response.write6;<ay of the wee!/ ;"Wee!<ay6<ate99
42
<ay of the wee!/ C
14response.write6;<ay of the month/ ;"<ay6<ate9942 <ay of the month/ FQ
14response.write6;+urrent .ear/ ;".ear6<ate9942 +urrent .ear/ GIFI
14response.write6;+urrent .ear/ ;"5ight6.ear6<ate9G99
42
+urrent .ear/ FI
14response.write6;$oday is/
;"Wee!<ay=ame6Wee!<ay6<ate99942
$oday is/ $hursday
14response.write6;#our Part/ ;"6hour6now99942 #our part/ GB
14response.write6;Minute Part/ ;"Minute6now699942 Minute part/ HF
14response.write6;Second Part/ ;"Second6now699942 Second part/ HH
Processin& !orms usin& ASP
.ou can process #$M% forms using these two powerful ASP ob>ects Response and Reuest.
Response outputs the value to a page and Re(uest retrieves values from an ob>ect. $a!e a
loo! at the following e?ample/
1form name:8userAorm8 method:8post8 action:8userAorm.asp82
)nter a user name/ 1input type:8te?t8 name:8user=ame8
siVe:8GI82
)nter a password/ 1input type:8password8 name:8password8
siVe:8GI82
1inpute type:8submit8 name:8submit8 value:8Send82
13form2
5esult
)nter a user name/
)nter a password/
Send
We >ust created #$M% form and tell the browser to process the form using the file
!user"orm.asp!. $he following is userAorm.asp file that writes the values from the form.
1html2
1head2
1title2Process form Info13title2
13head2
1body2
.ou have typed the user name 14:5equest.Aorm6;user=ame;942
and the password 14:5equest.Aorm6;password;942.
13body2
13html2
$ype something in the te?t
bo?es and hit submit button
to see the result of this
e?ample. What you will see
is the result of this code.
$he form will pass the
information to userAorm.asp
file which then will use the
power of Reuest to write
this information.
Form Processin& Example )
.ou can store value retrieved from form into variables in order to use these value whatever way
you want. $a!e a loo! these at this e?ample which is little bit more comple? then previous one.
1html2
1head2
1title2Aorm )?ample G13title2
13head2
1body2
1p21b2$his e?ample process basic form elements13b2
1form method:;P0S$; action:;formProcess.asp;2
1p2.our name/ 1input type:;te?t; name:;=ame; siVe:;GI;21br2
Status/ 1input type:;radio; value:;+ustomer; name:;status;2+ustomer 1input type:;radio;
name:;status; value:;&isitor;2&isitor1br2
<o you own any of these truc!s/1br2
1input type:;chec!bo?; name:;truc!; value:;%and +ruiser;2%and +ruiser1br2
1input type:;chec!bo?; name:;truc!; value:;Sequoia;2Sequoia1br2
1input $.P):;chec!bo?; name:;truc!; value:;H5unner;2H5unner1br2
1input $.P):;chec!bo?; name:;truc!; value:;#ighlander;2#ighlander1br2
1input $.P):;chec!bo?; name:;truc!; value:;$undra Access +ab;2$undra Access +ab1br2
+ar of +hoice/1select siVe:;F; name:;product;2
1option value:;M5G Spyder;2M5G Spyder13option2
1option value:;+elica;2+elica13option2
1option value:;Matri?;2Matri?13option2
1option value:;Avalon;2Avalon13option2
1option value:;+amry;2+amry13option2
1option value:;+orolla;2+orolla13option2
1option value:;)cho;2)cho13option2
1option value:;Prius;2Prius13option2
1option value:;5A&H )&;25A&H )&13option2
13select21br2
)nter some general comments about what you thin! about $oyota cars/1br2
1te?tarea rows:;C; name:;+omments; cols:;CI;213te?tarea21br2
1align:;center;21input type:;submit; value:;Submit; name:;submit;21br2
13form2
13body2
13html2
5esult of the above code
This example process basic !orm
elements
.our name/
Status/ +ustomer &isitor
<o you own any of these truc!s/
%and +ruiser
Sequoia
H5unner
#ighlander
$undra Access +ab
+ar of +hoice/
Any comments about $oyota cars/
Submit
+ode for formProcess.asp
1html2
1head2
1title25esult of your information13title2
13head2
1body2
14
dim name status truc! car comments
name:5equest.Aorm6;=ame;9
status:5equest.Aorm6;status;9
car:5equest.Aorm6;car;9
comments:5equest.Aorm6;comments;9
truc!:5equest.Aorm6;truc!;9
42
.our name/ 1b214:name4213b21br2
Status/ 1b214:status4213b21br2
.our favourite car is/ 1b214:car4213b21br2
.ou currently own these truc!s/1b2 14:truc!
4213b21br2
.our comments about $oyota products/1b21
4:comments4213b2
13body2
Writin& to a Text File usin& ASP
.ou can write to or read from a te?t file using ASP. $he following is simple e?ample that
illustrates how to create te?t file and write some information to it.
1html2
1title2+reate t?t file 13title2
1body2
14
Set
#et
file$%&=#erver.'reate$%&ect(!#criptin(."ile#)st
em$%&ect!) creates the instance of the file
ob>ect. set
file1=file$%&.'reate*e+t"ile(!,asp,*e+t"ile.t+t!)
file0b>:Server.+reate0b>ect6;Scripting.AileSyst
em0b>ect;9
set
fileF:file0b>.+reate$e?tAile6;WaspW$e?tAile.t?t;9
fileF.Write%ine6;$his is what goes to the te?t file
that would be created;9
fileF.Write%ine6;$his is the second line of the
te?t file;9
fileF.+lose
set fileF:nothing
set file0b>:nothing
42
13body2
13html2
creates the actual file *e+t"ile.t+t within the
specified path. -rite.ine() writes the quoted
line of te?t then we close the file and set
instance bac! to nothing.
Readin& !rom a Text File
5eading from a te?t file is also very easy and similar to writing to it. $he following e?ample
illustrates how to read from a te?t file.
1html2
1body2
14
Set file0b>:Server.+reate0b>ect6;Scripting.AileSystem0b>ect;9
Set
listAile:file0b>.0pen$e?tAile6Server.MapPath6;Wcli!toprogramWaspWlist.t
?t;9 F9
do while listAile.At)nd0fStream : false
5esponse.Write6listAile.5ead%ine9
5esponse.Write6;1br2;9
loop
listAile.+lose
Set listAile:=othing
Set file0b>:=othing
42
13body2
13html2
5esult
Welcome
this is line one
this is line two
this is line three
this is line four
this is line five
$his e?ample displays all
the lines of the te?t file
one by one.
$o display all the lines at once without line brea!s simply replace the lines starting with do while
and ending with loop to 5esponse.Write6listAile.5eadAll9.
$o display the first line of the te?t file use 5esponse.Write6listAile.5ead%ine9.
$o s!ip line of a te?t file uselistAile.S!ip%ine
$o s!ip part of line of a te?t uselistAile.S!ip6G9. $his will s!ip G characters.
$o write an empty line use Write'lan!%ines
Also you can assign the line to a variable li!e thiste?t:listAile.5ead%ine
Adding Data to Access Database
$o add data to a database table you need an e?isting database plus the table to add the data
to. %et us assume that you have Access <atabase file name "eedBac/.md% in the same folder
as this file with the following table/
tblAeeds
Field
"ame
%ata Type
Field
Size
userSid
Autonumbe
r
Q
=ame $e?t HC
+omments $e?t GII12
$o add a data to the table t%l"eeds first we will have to create a form to enter the data and then
open the database and ma!e the connection.
#ere is the form to enter the data before adding to the database/
Form Example Result
1html2
1head2
1title2 Adding to database e?ample 13title2
1script type:;te?t3>avascript;2
1X**
function validate69
Y
if6document.form.name.value::;;9
Y
alert6;=ame is missing;9E
return falseE
Z
if6document.form.comments.value.length1Q9
Y
alert6;=ot enough comments entered;9E
return falseE
Z
else
=ame/
+omments
/
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
Y
return trueE
Z
Z
33**2
13script2
13head2
1body2
1form name:;form; method:;post; action:;save.asp;2
=ame/ 1input type:;te?t; name:;name;
ma?length:;HC;2 1br2
+omments/ 1te?tarea cols:;GI; rows:;Q;
name:;comments; ma?length:;GII;2 13te?tarea21br2
1input type:;submit; name:;Save; value:;Submit;
on+lic!:;return validate69E;2
13form2
13body2
13html2
submit button.
Save the file as EnterData.html or
EnterData.asp.
Now, you insert the new record to the database using the information provided through
EnterData.asp. ere is the code to do this!
sa*e+asp
14
<im +onn
<im 5s
<im sql
L+reate an A<0 connection and recordset ob>ect
Set +onn : Server.+reate0b>ect6;A<0<'.+onnection;9
Set 5s : Server.+reate0b>ect6;A<0<'.5ecordset;9
LSet an active connection and select fields from the database
+onn.0pen ;<5I&)5:YMicrosoft Access <river 6M.mdb9ZE <'[:; "
Server.MapPath6;Aeed'ac!.mdb;9
sql: ;S)%)+$ name comments A50M tblAeedsE;
LSet the loc! and cursor type
5s.+ursor$ype : G
5s.%oc!$ype : B
5s.0pen sql +onn L0pen the recordset with sql query
5s.Add=ew LPrepare the database to add a new record and add
5s.Aields6;name;9 : 5equest.Aorm6;name;9
5s.Aields6;comments;9 : 5equest.Aorm6;comments;9
5s.Kpdate LSave the update
5s.+lose
Set 5s : =othing
Set +onn : =othing
42
$he third field 6userSno9 of our table is auto generated and sequentially will accommulate it self
on each addition of new record.
.ou redirect the user to another page when the record is added to the database using
14response.redirect6;view.asp;942
"fter the data is added to the database, the ne#t thing you may want do is view to see what is
added. The code is very similar.
This code bellow displays the fields.
*iew+asp
14
<im +onn
<im 5s
<im sql
Set +onn : Server.+reate0b>ect6;A<0<'.+onnection;9
Set 5s : Server.+reate0b>ect6;A<0<'.5ecordset;9
+onn.0pen ;<5I&)5:YMicrosoft Access <river 6M.mdb9ZE <'[:; "
Server.MapPath6;Aeed'ac!.mdb;9
sql: ;S)%)+$ name comments A50M tblAeedsE;
5s.0pen sql +onn
<o While not 5s.)0A
5esponse.Write 6;:::::::::::::::::::::::::::::::::::::::::::::;";1br2;9
5esponse.Write 6;=ame/ ; " ;1font color:LredL2; " 5s6;name;9 " ;13font2;9
5esponse.Write 6;1br2;9
5esponse.Write 6;+omment/ ; " ;1font color:LredL2; " 5s6;comments;9 " ;13font2;9
5esponse.Write 6;1br2;9
5s.Move=e?t
%oop
5s.+lose
Set 5s : =othing
Set +onn : =othing
42
$iew this file
,pdate a record
$here are more than one way to do things. Aor this e?ample we are going to list items from the
database so that you can select a record using radio button.
+ode to list records from t%l"eeds
1html2
1body 2
Select name to update.
14
<im +onn 5s sql
Set +onn : Server.+reate0b>ect6;A<0<'.+onnection;9
Set 5s : Server.+reate0b>ect6;A<0<'.5ecordset;9
+onn.0pen ;<5I&)5:YMicrosoft Access <river 6M.mdb9ZE <'[:; "
Server.MapPath6;Aeed'ac!.mdb;9
sql: ;S)%)+$ M A50M tblAeedsE;
5s.0pen sql +onn
5esponse.Write ;1A05M name:LKpdateL method:LpostL action:LtoKpdate$.aspL2;
5esponse.Write ;1table border:F cellspacing:I2;
5esponse.Write ;1tr2;";1td colspan:LBL align:LcenterL2;";Select a comment to update and clic!
select;";13td2;";13tr2;
5esponse.Write ;1tr2;";1th align:LcenterL colspan:LGL2;";=ame;";13th2;";1th
align:LcenterL2;";+omment;";13th2;";13tr2;
if =0$ 5s.)0A then
<o While not 5s.)0A
5esponse.Write 6;1tr2;9
5esponse.Write 6;1td2;";1input type:LradioL name:LI<L value:;"5s6;userSid;9";2;";13td2;9
5esponse.Write 6;1td2;"5s6;name;9";13td2;9
5esponse.Write 6;1td2;"5s6;comments;9";13td2;9
5esponse.Write 6;13tr2;9
5s.Move=e?t
%oop
else
5esponse.Write6;=o records found;9
end if
5esponse.Write6;1tr2;";1td colspan:LBL align:LcenterL2;";1input type :LsubmitL name:LsubmitL
value:LSelectL 2;";13td2;";13tr2;9
5esponse.Write ;13table2;
5s.+lose
Set 5s : =othing
Set +onn : =othing
42
13form2
13body2
13html2
+lic! here for result
KserSI< is a unique field which identifies the selected record. When the user selects record
and clic!s on Select the information is processed in the to0pdat*.asp file.
toKpdate$.asp file allows the user edit the record
1html2
1body2
1form name:;updated; action:;update+omment.asp; method:;post;2
14
<im I< name comments
I<: 5equest.Aorm6;I<;9
name : 5equest.Aorm6;name;9
comments:5equest.Aorm6;comments;9
if name:;; then
5esponse.Write ;.ou did not select a name to updateX;
)lse
<im +onn 5s sql
Set +onn : Server.+reate0b>ect6;A<0<'.+onnection;9
Set 5s : Server.+reate0b>ect6;A<0<'.5ecordset;9
+onn.0pen ;<5I&)5:YMicrosoft Access <river 6M.mdb9ZE <'[:; "
Server.MapPath6;Aeed'ac!.mdb;9
sql: ;Select M A50M tblAeeds W#)5) userSid:;"I<
5s.0pen sql +onn
if =0$ 5s.)0A then
42
1table border:F cellspacing:I2
1tr21td colspan:;G; align:;center;2Kpdate and save13td213tr2
1tr2
1td2=ame/ 13td2
1td21input type:;te?t; name:;name; siVe:;BI; ma?length:;HC; value:;14:5s6;name;9
42;213td2
13tr21tr2
1td2+omment/ 13td2
1td21input type:;te?t; name:;comments; siVe:;BI; ma?length:;GCI; value:;1
4:5s6;comments;942;213td2
13tr21tr2
1td colspan:;G; align:;center;21input type:;submit; name:;submit; value:;Save;213td2
13tr2
13table2
13form2
14
else
5esponse.Write6;5ecord does not e?ist;9
end if
+onn.+lose
Set +onn : =othing
)nd If
42
13body2
13html2
After the new data is entered the ne?t thing is to save the data and the following is the file to
do that.
update+omment.asp saves the new information
1html2
1body2
14
<im namecomments userSid
I< : 5equest.Aorm6;I<;9
name : 5equest.Aorm6;name;9
comments:5equest.Aorm6;comments;9
if name:;; 05 comments:;; then
5esponse.Write ;A field was left empty please try againX;
)lse
<im +onn 5s sql
Set +onn : Server.+reate0b>ect6;A<0<'.+onnection;9
Set 5s : Server.+reate0b>ect6;A<0<'.5ecordset;9
+onn.0pen ;<5I&)5:YMicrosoft Access <river 6M.mdb9ZE <'[:; "
Server.MapPath6;Aeed'ac!.mdb;9
sql: ;Kpdate tblAeeds Set name:L;" name " ;L comments:L; " comments ";L W#)5)
userSid:; " I<
5s.0pen sql +onn
+onn.+lose
Set 5s:=othing
Set +onn : =othing
5esponse.Write ;Successfully Kpdated;
)nd If
42
13body2
13html2

You might also like