GuestBook

A simple guestbook application. You'll need a SQLite database named **guestbook.db** with a table called //guestbook//. That //guestbook// database is made up of three columns:


 * 1) **name** varchar(100)
 * 2) **message** text
 * 3) **id** bigint

The following is the Run BASIC code.

code format="blitzbasic" [start] cls

 DISPLAY  ' Starts the table html " " wait

 ADDS THE NEW MESSAGE  [addnew] yn$ = #yn contents$ ym$ = #ym contents$

if yn$ = "" then yn$ = "Anonymous Coward" else yn$ = yn$ if ym$ = "" then ym$ = "Got nuthin to say." else ym$ = ym$

Call AddMsg yn$ ym$ goto [start]

 FUNCTION AND SUB AREA  ' Counts messages and gets a new, high, unique id number function CountMsg$ sqliteconnect #msg, "guestbook.db" query$ = "select count(*) from guestbook" #msg execute(query$) result$ = #msg nextrow$("") lastcount = val(result$) + 1 #msg disconnect CountMsg$ = str$(lastcount) end function

' Lists all messages sub ListMessages sqliteconnect #msg, "guestbook.db" query$ = "select * from guestbook order by id desc" #msg execute(query$) while #msg hasanswer result$ = #msg nextrow$("-|-") Call BuildMsg result$ wend #msg disconnect end sub

' Inserts the new message into the database sub AddMsg nam$ msg$ lastcount$ = CountMsg$ sqliteconnect #msg, "guestbook.db" query$ = "insert into guestbook values ('" + nam$ + "', '" + msg$ + "', " + lastcount$ + ")" #msg execute(query$) #msg disconnect end sub

' Generates a single guestbook message sub BuildMsg text$ name$ = "" msg$ = "" id$ = "" commacnt = 0 cnt = 1

while cnt <= len(text$) temp$ = mid$(text$, cnt, 1)

if mid$(text$, cnt, 3) = "-|-" then commacnt = commacnt + 1 cnt = cnt + 3 else select case commacnt case 0 name$ = name$ + temp$ case 1 msg$ = msg$ + temp$ case 2 id$ = id$ + temp$ end select cnt = cnt + 1 end if wend

html "" html " " + name$ + " " + msg$ + " " html " "

end sub code