Classic Guestbook made with Flash and ASP/PHP

The ASP Code

This is the ASP code... The data is stored in guestbook.mdb, with a table called tbguest, and two fields; gid and gcomments.

Guestbook.asp

dim filename 'name of database file
dim maxfld 'record counter
dim cmtStr ' comment string
filename=server.mappath("/") & "\" & "guestbook.mdb" // path to access database

'Set connection string for access database

cs="Provider=Microsoft.jet.oledb.3.51;"
cs=cs & "Persist Security info=false;"
cs=cs & "data source="
cs=cs & filename & ";"

set adocon=server.createobject("adodb.connection") 'create connection object
adocon.open cs 'open connection
'fetch variables from flash
txtname=request.form.item("txtname")
txtemail=request.form.item("txtemail")
txtwebsite=request.form.item("txtwebsite")
txtcomments=request.form.item("txtcomments")

'Create recordset and get no of records in the database.

set rs_max_value=adocon.execute("select max(val(gid)) as x from tbguest")
maxfld=rs_max_value.fields("x")

'Increment the no by one.

if isnull(maxfld) then
maxfld=1
else
maxfld=maxfld+1
end if
rs_max_value.close ' close the recordset object.


'If new data is submitted
if request.form.item("submit1")="Y" then


'create a new string in HTML format using variables
cmtstr = "Name: <b>" & txtname & "</b><br>Email: <b><u><a href=" & "'" & "mailto:" & txtemail & "'" & ">" & txtemail & "</a></u></b><br>"
cmtstr = cmtstr & "Website: <b><u><a href=" & "'" & txtwebsite & "'" & " target=" & "'" & "_blank" & "'" & ">" & txtwebsite & "</a></u></b><br>"
cmtstr = cmtstr & "Comments: <b>" & txtcomments & "</b><br>"
cmtstr = cmtstr & "<i>Posted on: " & Now() & "<br>"

dim commandobject
dim insertionstr

set commandobject=server.createobject("adodb.command") 'create a command object
set commandobject.activeconnection=adocon // set active connection to the command object

insertionstr="insert into tbguest (gid,gcomments) values (?,?)" ' sql query for insertion

commandobject.commandtext=insertionstr
commandobject.prepared=true
commandobject.parameters.append commandobject.createparameter("gid",3,,1000)
commandobject.parameters.append commandobject.createparameter("gcomments",200,,500)

'Assign values to command objects
commandobject("gid")=maxfld
commandobject("gcomments")=cmtstr

commandobject.execute 'execute the query
set commandobject=nothing // destroy the command object
end if

dim llimit
dim hlimit

llimit=request.form.item("lowlimit")
hlimit=request.form.item("highlimit")

'Calculate total entries in Access
dim sqlstr
dim flashstr
sqlstr="select max(gid) as x from tbguest"
set rs_flash=adocon.execute(sqlstr)
totalent=rs_flash.fields("x")
rs_flash.close

'Following code is for displaying entries from lowlimit to highlimit
if totalent>0 then
sqlstr="select * from tbguest order by gid desc"
set rs_flash=adocon.execute(sqlstr)
dim strflash
rs_flash.movefirst
if totalent>=hlimit then
hlimit=totalent
end if
upto=llimit-1
j=0
for j=1 to upto
rs_flash.movenext
next
i=0
for i=1 to (hlimit-llimit)+1
if rs_flash.eof then exit for
strflash=strflash & rs_flash.fields("gcomments")
rs_flash.movenext
next
strflash=strflash & "<br><br>" & " ::::::::::::: Nothing Below This ::::::::::::::: "
else
strflash=":: Nothing to Display ::"
rs_flash.close
end if
response.write("&txtll=" & llimit & "&txthl=" & hlimit & "&totalentries=" & totalent & "&txtmain=")
response.write(strflash) // variables for flash movie.
adocon.close // destroy the connection

You might also like...

Comments

About the author

Pradeep Mamgain India

Woking as a VB programmer. Use my free type in writing code and maintaining my site. I have an exclusive collection of PHP stuff for windows at my site.

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Before software should be reusable, it should be usable.” - Ralph Johnson