The following basic steps are indispensable for the complex BBS.
(1) database, used to store posted posts! ----- Name: bbs. mdb (note: the database I selected here is Access)
(1) bbs. mdb
Open the database and create a table named bbs
This table has several fields:
Id (automatically number the post). Its data type is set to "automatically number"
Name (used to store the author of the publication). The data type is "text"
Title (used to store the topic of a post). The data type is "text"
Body (used to store the Post content), the data type is "remarks"
========================================================== ========================================================== ========================================================== =====
(2) If a database exists, you must connect to the database. This file is used to connect to the database: ---- name: conn. asp
(2) conn. asp (this is the code for connecting to Access)
The source code is as follows:
<%
Server. scriptTimeout = "10"
Connstr = "DBQ =" + server. mappath ("bbs. mdb") + "; DefaultDir =; DRIVER = {Microsoft Access Driver (*. mdb )};"
Set conn = Server. CreateObject ("ADODB. connection ")
Conn. open connstr
%>
========================================================== ========================================================== ========================================================== =====
(3) file used for posting ---- name: say. asp
(3) say. asp
Source code:
<Form method = "POST" action = "save. asp">
<P> name: <input type = "text" name = "name" size = "20"> </p>
<P> title: <input type = "text" name = "title" size = "91"> </p>
<P> Content: </p>
<P> <textarea rows = "11" name = "body" cols = "97"> </textarea> </p>
<P> </p>
<P> <input type = "submit" value = "submit" name = "B1"> <input type = "reset" value = "reset" name = "B2"> </p>
</Form>
The code for this file uses the html syntax !!! The point is: <form method = "POST" action = "save. asp">, which sends the content entered by the user to the save. asp file!
========================================================== ========================================================== ========================================================== =====
(4) save the post content file ----- name: save. asp
4. save. asp
Source code:
<! -- # Include file = "conn. asp" -->
<% Name = Replace (Request. Form ("name "),"'","''")
Title = Replace (Request. Form ("title "),"'","''")
Body = Replace (Request. Form ("body "),"'","''")
%>
<% If name = "" or title = "" or body = "" then %>
Please <a href = "*****: history. go (-1)"> BACK up </a> and enter the complete information before posting!
<% Else %>
<% Set savebbsexample conn.exe cute ("insert into bbs (name, title, body) values ('" & name & "', '" & title &"', '"& body &"') ") %>
Posted successfully! <A href = "index. asp"> View Post </a>
<% End if
Set savebbs = nothing
%>
This is more complicated !!! I 'd like to explain the key points!
First sentence: <! -- # Include file = "conn. asp" -->, which means to insert the conn. asp file, that is, to connect to the database!
Asp statements must be included in the format of <%>, but the statements for inserting files are not used !!!
It seems like this sentence is used!
<% @ Language = "Jscript" %>
<%
Response. write ("stuhack.com ");
%>
The following sentence:
Name = Replace (Request. Form ("name "),"'","''")
Title = Replace (Request. Form ("title "),"'","''")
Body = Replace (Request. Form ("body "),"'","''")
"Replace (Request. Form (" name ")," '"," ''") "means to receive data from the text box named name in the Form,
"Name = Replace (Request. Form (" name ")," '"," ''") "stores the sent data in the name variable,
If you do this: "abc123 = Replace (Request. Form (" name "),"'","''")"
The data sent from the text box named name in the form is stored in the abc123 variable.
Next, if name = "" or title = "" or body = "" then
Determine whether the name, title, and body variables are empty, that is, "". If so, execute this statement:
"Please <a href =" *****: history. go (-1) "> BACK up </a> and enter the complete information before you can post the post !"
This statement is an html syntax that everyone can understand!
"<% Else %>" means "when if ...... If then is not true (that is, all content has been filled in), run the following statement:
"<% Set savebbs+conn.exe cute (" insert into bbs (name, title, body) values ('"& name &"', '"& title &"', '"& body &"') ") %>
Posted successfully! <A href = "index. asp"> View Post </a>"
"Set saveappsconn.exe cute" is a fixed statement, but savebbs can be modified by itself. "=" It is difficult to explain the following:
Insert into bbs (name, title, body) refers to the table named bbs (the table already created when the database is created)
Insert the name, title, and body fields. What should I insert? View next values ('"& name &"', '"& title &"', '"& body &"')")
Values indicates a value.
Insert vector name, title, body, and vector in the format of '"& name &"'
Finally, end if is to end if ...... Then
Set savebbs = nothing can be said to be disabled:
Set savebbsaskconn.exe cute ("insert into bbs (name, title, body) values ('" & name & "', '" & title &"', '"& body &"')")
========================================================== ========================================================== ========================================================== ===
(5) file ------ name: index. asp
Source code:
<! -- # Include file = "conn. asp" -->
<B> <a href = "say. asp"> Post </a> </B> <br>
<Div align = "center">
<Center>
<Table border = "0" cellpadding = "0" cellspacing = "0" style = "border-collapse: collapse; "bordercolor =" #000000 "width =" 100% "height =" 26 ">
<Tr>
<Td width = "17%"> <B> Author </B> </td>
<Td width = "83%"> <B> Topic </B> </td>
</Tr>
</Table>
</Center>
</Div> <% I = 1
Set showbbs=conn.exe cute ("select * from bbs order by id desc ")
Do while not showbbs. eof
%>
<Div align = "center">
<Center>
<Table border = "0" cellpadding = "0" cellspacing = "0" style = "border-collapse: collapse; "bordercolor =" #000000 "width =" 100% "height =" 20 ">
<Tr>
<Td width = "17%"> <% = showbbs ("name") %> </td>
& Lt; td width = "83%" & gt;
<A href = "show. asp? Id = <% = showbbs ("id") %> "> <% = showbbs (" title ") %> </a> </td>
</Tr>
</Table>
</Center>
</Div> <% I = I + 1
If I> 50 then exit do
Showbbs. movenext
Loop
Showbbs. Close
Set showbbs = nothing
%>
This file will not be mentioned in a single sentence.
The main focus is on the following:
Set showbbs=conn.exe cute ("select * from bbs order by id desc ")
It means to query data from the bbs data table in the database and sort the data by id,
Another sentence: <% = showbbs ("name") %>
It is the data that shows the name field in the data table. Here showbbs is set showbbs = ...... Showbbs in
I = 1 and I = I + 1 in the code
If I> 50 then exit do
Showbbs. movenext
Loop
Showbbs. Close
Set showbbs = nothing
These statements are cyclic statements. Only 50 posts are displayed!
If I> 50 then exit do 50 can be modified
However, we have to paging the post in the forum. Because the paging statement is too complicated, I don't want to talk about it anymore. I will get it done when I understand it.
Another useful sentence is:
<A href = "show. asp? Id = <% = showbbs ("id") %> "> <% = showbbs (" title ") %> </a>
Hyperconnection: show. asp? Id = <% = showbbs ("id") %>. Note: hyperconnections include the Post id,
It will be useful in the show. asp file.
========================================================== ========================================================== ========================================================== =
(6) the file that displays the content of the post, that is, the page displayed after clicking the title ----- name: show. asp
Source code:
<! -- # Include file = "conn. asp" -->
<% Id = request. querystring ("id") %>
<% Set showaskconn.exe cute ("select * from bbs where id =" & id & "") %>
<A href = "index. asp">
<B> Return to the home page </B> </a> <br> <B> <a href = "say. asp "> Post </a> </B> <br> <Table border = "1" cellpadding = "0" cellspacing = "0" style = "border-collapse: collapse "bordercolor =" #111111 "width =" 100% "height =" 180 ">
<Tr>
<Td width = "21%" height = "22"> <B> Author: </B> <% = show ("name") %> </td>
<Td width = "79%" height = "22"> <B> Topic: </B> <% = show ("title") %> </td>
</Tr>
<Tr>
<Td width = "100%" colspan = "2" height = "158" valign = "top"> <B> <br> content: </B> <% = show ("body") %> </td>
</Tr>
</Table> <% set show = nothing %>
Statement --- excellent statement:
Id = request. querystring ("id ")
After explaining the index. asp file, I have already mentioned: show. asp? Id = <% = showbbs ("id,
Id = request. querystring ("id") is to read the id value in the address bar,
Because the hyperjoin in the index. asp file is clicked, the address bar is http ://............ /Show. asp? Id = number,
Therefore, show. asp uses the id = request. querystring ("id") statement to read the number.
Then use: set showdeskconn.exe cute ("select * from bbs where id =" & id &"")
A post that queries a data table whose id is the number read at this time, that is, where id = "& id &"
Last <% set show = nothing %>