Preface: Nowadays, there are forums everywhere on the Internet, but I wonder if you have ever encountered such a situation: looking for the content you want in the messy discussion information is a very time-consuming and labor-intensive thing. Later, you will I don’t want to go to any forum anymore. So can we add an audit function to the content of our website forum? That is, all articles posted by netizens to the forum will not be displayed immediately. They must be reviewed by the webmaster or moderator. If they are deemed valuable and necessary to recommend to other netizens, they will be published. Otherwise, delete it to avoid wasting space and making it look a bit like a highlight area. In this way, your forum can provide more clear and beneficial content than ordinary forums. Putting it on your website should attract more netizens to visit. This idea can certainly be realized, and I will briefly introduce how to make it below.
Note: This article is suitable for readers who have a certain understanding of ACCESS database, HTML, and ASP.
1. Forum structure analysis
Through the above functional requirements analysis, we can divide the production of the forum into four parts:
(1) Netizen registration and management module: Because the webmaster or moderator is introduced, it must be able to control it in the forum Authenticate. The function of this module is to manage registered netizens and provide relevant queries. For example, query all published articles by a specified author, query the ten netizens who have published the most articles, etc. If your forum is not very large, this module can be omitted to only have the function of moderator authentication, and remove the parts about registration and query.
(2) Article display module: displays all articles that have been reviewed by moderators and deemed worthy of recommendation.
(3) Article publishing module: Provides a place for registered netizens to publish their opinions, and wait for review by moderators after publication.
(4) Article review module: Moderators process all articles that have been published on the website but have not been reviewed, and have decided whether to publish or delete them.
After understanding the specific functional requirements, you can start the design of the forum according to the module. Of course, these modules only functionally divide the forum structure, and they cannot actually be designed completely independently. For such smaller applications, there is no need for a complete modular design. It may be easier to write program code directly with good planning.
There are generally two ways to implement a forum: using files or databases. Relatively speaking, using a database is simpler and more efficient, can provide better control over the forum, and can also provide some verification and protection for the data. Here I am using the ACCESS database. For general small and medium-sized applications, ACCESS should be able to do the job.
From the above analysis, we can know that there should be four tables. Below I give the structure of each table.
(1) Author table (used to store author information):
ID: Text type, required. It’s a netizen’s code name.
Password: Text type, required.
Nickname: Text type, required.
EMAIL: Text type, required.
Position: Numeric type, required. -1 represents ordinary netizens, 0 represents webmasters. Numbers greater than 0 represent moderators.
Number of articles: numeric type, required. The total number of articles published by netizens.
Name: text type, optional.
Gender: text type, optional.
Phone: Text type, optional.
(2) Content table (used to store specific article content and related information):
ID: Automatically number and index it to speed up search.
Kanban ID: numeric type, from the Kanban list, indicating the Kanban board the article belongs to.
Topic ID: Numeric type, from the topic table, indicating the topic to which the article belongs.
Author ID: text type, from the author table, indicating the author of the article.
Date: Date/time type, the preset initial value is the function NOW(), which automatically takes the current system time as its value.
Title: Text type. The title of the article.
Publish: Yes/No type, "True" means the article has been reviewed and can be published; "No" means the article has yet to be reviewed.
Recommendation: Numeric type, the recommendation degree of the article.
Content: Remark type, specific content of the article.
Number of clicks: Number type, the number of clicks on the article.
(3) Kanban list (used to store information about the kanban):
ID: Automatic number. Similarly, an index is also set for it.
Name: Text type, the name of the board.
Moderator: Text type, ID of the board moderator.
Number of Topics: Numeric type, the number of topics included in the board.
(4) Topic table (used to store information about topics):
ID: Automatically number and set an index for it.
Title: Text type, indicating the topic name.
Kanban board: Number type, from the Kanban board list, indicating the Kanban board to which the topic belongs.
Number of articles: Number type, the number of articles contained in the topic.
All tables have been designed, but the design of the database is not yet complete, so we still need to establish relationships between tables, so that the database can perform some correlation checks to avoid data errors. Another benefit of establishing relationships between tables is that complex JOIN queries can be easily established through it.
Usually when we operate a database in ASP, we use queries generated during execution, which are then passed to the database for interpretation and execution. And here we are going to use stored queries. Stored procedures have more advantages than execution-time queries.
It is stored in the database and is independent of the ASP program code, making it easier to create and modify, and the query efficiency is higher and faster. It can be debugged and then used in the ASP page, which can avoid many problems. And ASP program code that uses stored queries is easier to read and modify. Maybe everyone is annoyed by using SQL queries in ASP, especially those commas, semicolons, etc., which can cause errors if you are not careful. After using stored queries, you don't have to worry about these problems. Of course, there are some things you need to pay attention to when using pre-stored programs. I will explain how to use them in detail later. It is very easy to create a stored program in ACCESS, so I won't say more about it here. Here I only give the SQL statement program code for each query.
I have saved all the queries to be used in the database as pre-stored programs. The main ones are as follows:
(1) Query articles by ID:
SELECT topic table. Title AS topic name, Kanban list. Name AS Kanban name, Table of contents.*
FROM topic table INNER JOIN (content table INNER JOIN kanban list ON content table.kanban ID = kanban list.ID) ON topic table.ID = content table.topic ID
WHERE (((content table.ID)=[articleid]));
(2) Moderator password query:
SELECT Kanban list.Board owner, author table.Password
FROM author table INNER JOIN kanban list ON author table.ID = kanban list.board owner
WHERE (((kanban list.ID)=[id];
(3) Query the author:
SELECT author table.*
FROM author table
WHERE (((author table.ID)=[id]));
(4) Published article list:
SELECT [Content table].[ID], [Content table].[Title], [Content table].[Author ID ] AS author, [table of contents].[date], [table of contents].[recommendation], [table of contents].[number of clicks] AS number of clicks.
FROM table of contents
WHERE ((([Table of Contents].[Topic ID])=[TopicIndex]) And (([Table of Contents].[Published])=True));
Unpublished article list:
SELECT Table of Contents.ID AS Article id, topic table.ID AS topic id, topic table.title AS topic, content table.title AS title, content table.author ID AS author, content table.date AS date
FROM topic table INNER JOIN content table ON topic table.ID = content table.topic ID
WHERE (((Content table. Publish)=False) AND ((Content table. Kanban ID)=[boardid]));
(5) Topic list:
SELECT Topic table.*, Kanban list. Name AS Kanban name
FROM kanban list INNER JOIN topic table ON kanban list.ID = topic table.kanban
WHERE (((topic table.kanban)=[boardIndex]));
There are also some queries, because most of them are similar, I will not list them one by one.
In the above query statement, you can see some things surrounded by "[" and "]", which are query parameters. The parameter value needs to be given during execution, and then the parameter value is brought into the query statement before it can be executed. Another thing to note is that when establishing those INNER JOIN queries, you need to add the relationship between tables to the design view, otherwise the INNER JOIN query statement cannot be automatically generated.
At this point, the database design is finished, and the next work is ASP.
2. Construction
1. To build the main form
, you must first provide a form that allows netizens to enter registration information. These are HTML contents, and put them aside. Let's take a closer look at the ASP script that implements registration.
(1) Change the single quotation mark in the information to two single quotation marks, and add single quotation marks before and after
Function SqlStr(data)
SqlStr = "'" & Replace( data,"'", "''" ) & "'"
End Function
Note: This is a custom function used to convert single quotes (') in user input into two single quotes (''). In ASP, a string is surrounded by double quotes, so the "'" above represents a string with only one single quote. The reason why you need to replace one single quote with two single quotes is because in SQL statements, single quotes are used to represent variables. In order to avoid confusion, single quotes in the string must be represented by two single quotes. All user input must be embedded in the SQL statement as variables, so this function is essential.
(2) Storage preparation
id=Request("id")
password=Request("password")
nickname=Request("nickname")
email=Request("email")
sex=request("sex")
Note: It is not necessary to save the content from the user input form in a variable, but it makes it easier to read and write.
if Request("name")=""then name=" " else name=request("name")
if Request("phone")=""then phone=" " else phone=request("phone")
Because these contents are not required to be filled in, in order to prevent the user from not inputting anything and causing database operation errors, it must be Replace unfilled fields with spaces.
(3) Establish connection
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "driver={Microsoft AccessDriver (*.mdb)};dbq=" & Server.MapPath("bbssystem.mdb")
Note: This section is to establish a database connection. The name of the database is bbssystem.mdb. In this section The only thing to note is the application of the Server.MapPath function. Generally speaking, whenever a specific directory is involved, do not use the directory name directly, but use the Server.MapPath function instead. Making good use of functions such as Server.MapPath and Request.ServerVariables() can make your WEB application more portable.
Set cmd = Server.CreateObject("ADODB.Command")
(4) Query whether the author already exists
Set cmd.ActiveConnection = conn
cmd.CommandText = "Query Author"
ReDim param(0) 'Declare parameter array
param(0) = CStr(id) ' Cint cannot be ignored
Set rs = cmd.Execute(,param)
Note: This section is used to execute the stored program. There are many ways to execute queries in ADO, but for stored procedures you can only use the Command object. First, create a Command object called cmd, then set the conn connection object to the ActiveConnection property of the cmd object, set the name of the query to be executed "Query Author" to the CommandText property, and then assign values to the query parameters. We declared a parameter array param(0), because there is only one parameter in the query "Query Author", so the array has only one component. Generally, if there are several parameters in a query, a parameter array with a corresponding number of components must be declared. And the order in which the parameters appear corresponds to the order of the components in the array. In the process of using parameter query, special attention should be paid to the fact that the types of parameters must strictly match, otherwise an error will occur, so the above CStr() type conversion function is indispensable.
if not (rs.eof or rs.bof) then
response.write "Error, the ID number you entered has been occupied, please try another one!"
else
sql = "Insert Into author table (id, nickname, email, password, name, school, department, gender, phone number) Values("
sql = sql & SqlStr(id) & ","
sql = sql & SqlStr(nickname) & ","
sql = sql & SqlStr(email) & ","
sql = sql & SqlStr(password) & ","
sql = sql & SqlStr(name) & ",&", "
sql = sql & SqlStr(sex) & ","
sql = sql & SqlStr(phone) & ")"
conn.Execute sql
uses a SQL Insert statement to insert data into the database. In fact, this query can also be made into a pre-stored program and placed in the database. I was a little lazy:-) However, in comparison, you can also see the benefits of the pre-stored program. It is too troublesome to write the query during execution.
2. Build the article display module.
As mentioned before, a specific article belongs to the bulletin board and the main body. Therefore, when displaying articles, you have to go through the two pages of the bulletin board list and the subject list before you can get the list of articles under a specific topic.
(1) Board list display page:
<html>
<head>
<title>Kanban list</title>
<meta http-equiv="Content-Type"content="text/html; charset=GB2312">
</head>
(2) Open the connection and display the kanban list
< %Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "driver={Microsoft AccessDriver (*.mdb)};dbq=" & Server.MapPath("bbssystem.mdb")
sql = "select * from Kanban list"
set rs=conn.execute(sql)
%>
Note: A simple SQL query returns all the information about the kanban board to the record set RS. The following task is to display the recorded content and create a link to display the topic of the board on the corresponding board name.
<body bgcolor="#FFFFFF">
< h2 align="center">Kanban list</h2>
<table width="60%" border="0"cellspacing="0" cellpadding="0"align="center">
<tr bgcolor="#FFFFCC">
< td height="35" width="25%">Scanboard name</td>
<td height="35" width="21%">Moderator</td>
<td height="35" width="23%">Number of topics</td>
<td height="35" width="31%">Moderator login</td>
</tr>
Note: This part is to display the title of each column in the table. Here I do not use a unified function to display the contents of the RS record, because this allows more control over the appearance and style of the table. Use Although it is a bit cumbersome to get up, it is more flexible.
< %
do
boardid=rs("id")
boardname=rs("name")
boardmanager=rs("Board Owner")
response.write "<tr><td><a href=qBoard.asp?boardid="& boardid& "&boardname=" & boardname& ">" & boardname &"< /a>< /td>"
Note: This line is Importantly, when you click on the name of each board, you can connect to the page displaying the theme of the board. The program code looks a bit cumbersome. I'll break it down and explain it to you, and you'll understand. After clicking, the browser requests the qBoard.asp page with a parameter boardid, which represents the ID number of the board to be displayed. A question mark (?) is used to separate the request page and the parameter. Boardid is the variable set earlier, which contains the ID number of the corresponding board. This connection also contains another parameter boardname, which is used to pass the board name to the qBoard.asp page. Use "&" to separate multiple parameters. This parameter is not necessary. It is passed to avoid using boardid again to query the board name in qBorad.asp. Generally speaking, database operations should be used as little as possible, which can improve the performance of ASP pages. Because the Response.Write statement uses strings as parameters, the "&" connection character is used between the above strings and variables. The final result of the ASP page explanation should be like this
<td>< a href=qBoard.asp?boardid=1&boardname=System Board>System Board</a><td>.
response.write "< td>< a href=qAuthor.asp?author="&boardmanager & ">" &boardmanager & "< /a></td>"
response.write "< td>" &rs("number of topics") & "< /td>"
response.write "< td>< a href=managerlogin.asp?boardid="&boardid & ">Board processing< /a></td>< /tr>"
Note: In this table, in addition to the connection Displaying the content of the kanban theme, there is also a mosaic query part and a board service processing part. The moderator query can be implemented through qAuthor.asp. It simply retrieves the author information from the database and displays it. There is not much here. Said. The board processing is handled by the managerlogin.asp page. This belongs to the article review module, which I will explain in detail later.
rs.movenext
loop until rs.eof
%>
Note: Through a do... loop, all the messages in the record set are displayed.
</table>
<div align="center"><br>
Click on the board name to get the topic list, click on the board owner name to view the board owner's messages
</div>
</body>
</html>
< %
set rs=nothing
conn.close
set conn=nothing
%>
(3) Create the qBaord.asp page:
< %
boardid=request("boardid") 'Get the board ID number passed from the previous page
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "driver={Microsoft AccessDriver (*.mdb)};dbq=" & Server.MapPath("bbssystem.mdb")
Set cmd = Server.CreateObject("ADODB.Command")
Set cmd.ActiveConnection = conn
cmd.CommandText = "Topic List"
ReDim param(0) //Note: declare parameter array
param(0) = CLng(boardid)//Note: CLng cannot be ignored
Set rs = cmd.Execute( ,param)
%>
<html>
<head>
<title>Topic list</title>
<meta http-equiv="Content-Type"content="text/html; charset=GB2312">
</head>
<body bgcolor="#FFFFFF">
< h1 align="center"><%=rs("kanban name")%>Board theme list</h1>
<table width="80%" border="0"cellspacing="0" cellpadding="0"align="center">
<tr bgcolor="#FFFFCC">
<td width="89%" height="21">Theme</td>
<td width="11%" height="21">Number of articles</td>
</tr>
< %
do
topicid=rs("id")
topicname=rs("title")
sum=rs("number of articles")
response.write "< tr>< td><a href=qtopic.asp?topicid=" & topicid& "&boardname=" & boardname& ">" & topicname &"< /a>< /td>"
response.write "< td>" &sum & "< /td>< /tr>"
rs.movenext
loop until rs.eof
%>
</table>
</body>
</html>
Note: qBoard.asp lists all the topics under a certain forum. After clicking the topic name, you will enter the corresponding topic article list. This list is implemented by the ASP script qTopic.asp. The program code of Qtopic.asp is almost the same as qBoard.asp in essence, but there are differences in their respective details, and I am not going to go into more details here.
(4) After clicking the article title in the article list, you will enter the article content browsing page article.asp:
< %
articleid=request("articleid")
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "driver={Microsoft AccessDriver(*.mdb)};dbq=" & Server.MapPath("bbssystem.mdb")
Set cmd = Server.CreateObject("ADODB.Command")
Set cmd.ActiveConnection = conn
cmd.CommandText = "Query articles by id"
ReDim param(0) 'Declaration
param(0) = CLng(articleid) ' Cint cannot be ignored
Set rs = cmd.Execute( ,param)
author=rs("authorid")
title=rs("title")
data=rs("Date")
rate=rs("recommended degree")
boardid=rs("kanbanid")
topicid=rs("topicid")
boardname=rs("board name")
topicname=rs("topic name")
content=rs("content")
content=replace(content,vbCrlf,"</p><p>")
content="< p>" & content& "< /p>"
Note: This is something to note. The content field contains memo type text, which can contain newline characters. In the display of HTML, the newline character (that is, the vbCrlf constant) must be replaced by the HTML paragraph symbol. In this way, the connection between paragraphs will not disrupt the original input format. If you want to design better, you can use CSS to reset the <P> tag and set its test-indent attribute to achieve a space at the beginning of each paragraph.
(5) Add one to the number of clicks
sql="Update content table Set number of clicks=number of clicks+1Where ID=" & articleid
conn.execute sql
Note: There is a SQL statement here. When the page is displayed, the click count field in the corresponding table will be incremented by one, so that the number of article views can be counted and ranked in order. When executing the article statement, I found that: originally in the SQL statement, the embedded variable name should be distinguished by single quotes, but I did not add single quotes to the articleid variable here, and it actually passed, and I Writing like this has always caused errors in the past. I wonder if it is because of the new version of ADO.
set cmd=nothing
%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type"content="text/html; charset=GB2312">
</head>
<body bgcolor="#E9E9E4">
<table width="89%" border="0"cellspacing="0" cellpadding="0"align="center">
<tr bgcolor="#CCCCCC">
<td>Author:<font color="#FF3366"><a href="qauthor.asp?author=< %=author%>">< %=author%> < /a>< /font>Published date: < font color="#FF3333"><%=data%>< /font>
Kanban board:< font color="#FF3333"><a href="qboard.asp?boardid=< %=boardid%>">< %=boardname%>< /a>< /font>Board owner recommendation:< font color="#FF3333">#rate#</font>< /td>
</tr>
<tr bgcolor="#CCCCCC">
<td>Title:<font color="#FF3333"><%=title%>
Topic: < a href="qtopic.asp?topicid=<%=topicid%>"> < %=topicname%>< /a> < /font>< /td>
</tr>
<tr valign="top">
<td>
<hr>
< font color="#FF3366">Article content: < /font>< br>
<br>
< font color=blue>< %response.writecontent%>< /font>
<br>
<br>
</td>
</tr>
<tr valign="top">
<td height="18">
<table width="50%" border="0"cellspacing="0" cellpadding="0"align="right" bgcolor="#CCCCCC">
<tr>
< td width="0%"> < /td>
<td width="65%">About this topic<a href="submit.asp?topicid=< %=topicid%>&boardid=<%=boardid%>">Leave a comment< /a></td>
This The connection allows netizens to express their own opinions on the topic of this comment. This is what the next module will talk about, so I won’t mention it here.
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
< %
set rs=nothing
conn.close
set conn=nothing
%>
At this point, the article display part is also completed. Let’s take a look at how the article publishing part is implemented.
3. Construct the article publishing part.
The article publishing module only has two pages, one is the submit.asp mentioned earlier, which is used to provide the input form, and the other is subresult.asp, which is used to process the form input. The previous page is very simple. It is basically an HTML form. There is nothing much to talk about. Let’s take a look at the content of subresult.asp:
<html>
<head>
<title>Publish article</title>
<meta http-equiv="Content-Type"content="text/html; charset=GB2312">
</head>
<body bgcolor="#FFFFFF">
< %
author=request("author")
password=request("password")
topicid=request("topicid")
boardid=request("boardid")
content=request("content")
title=request("title")
Note: This section takes out the table content submitted in submit.asp and puts it in the corresponding variable.
<html>
<head>
<title>Publish article</title>
<meta http-equiv="Content-Type"content="text/html; charset=GB2312">
</head>
<body bgcolor="#FFFFFF">
< %
author=request("author")
password=request("password")
topicid=request("topicid")
boardid=request("boardid")
content=request("content")
title=request("title")
(1) Query whether the author exists
cmd.CommandText = "select * from author table where id='" & author &"'"
Set rs = cmd.Execute()
(2) Check permissions
cmd.CommandText = "select * from author table where id='" & author &"'"
Set rs = cmd.Execute()
Note: This section checks the author's permissions and handles errors accordingly if the account does not exist or the password is incorrect. Here you can see the usage of response.end, which is used to end the current ASP script. Combined with if statements, expected errors in the program can be handled. In a good WEB application, error handling is essential.
(3) Change the single quotation mark in the information to two single quotation marks, and add single quotation marks before and after
Function SqlStr(data)
SqlStr = "'" & Replace( data,"'", "''" ) & "'"
End Function
'Write to database
sql = "Insert Into content table (board id, topic id, author id, title, content)Values( "
sql = sql & SqlStr(topicid) & ","
sql = sql & SqlStr(boardid) & ","
sql = sql & SqlStr(author) & ","
sql = sql & SqlStr(title) & ","
sql = sql & SqlStr(content) & ")"
conn.Execute sql
%>
<h2>The article has been sent to the database and can be seen after the moderator reviews it <h2>
</body>
</html>
At this point, the article has been saved in the database. However, it cannot be displayed immediately and requires moderator approval. Next, let’s take a look at the management part of the forum.
4. The management part of the forum
is the core of our forum, but there is nothing special about its implementation. It's still the same old stuff: form processing, database query, and using ASP to combine them organically. When entering the article review mode (the board processing mentioned earlier), the most important thing should be to verify the moderator's identity. Let’s take a look at the moderator login page:
< %
boardid=request("boardid")
(Note: The boardid is passed by the connection to this page and is the ID of the board to be processed. Only through this can we know which board is being processed.)
Set conn = erver.CreateObject("ADODB.Connection")
conn.Open "driver={Microsoft AccessDriver (*.mdb)};dbq=" & Server.MapPath("bbssystem.mdb")
Set cmd = Server.CreateObject("ADODB.Command")
Set cmd.ActiveConnection = conn
cmd.CommandText = "Moderator password query"
ReDim param(0)
param(0) = CLng(boardid) //Note: CLng cannot be ignored
Set rs = cmd.Execute( ,param)
boardmanager=rs("Board Owner")
set cmd=nothing
%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type"content="text/html; charset=GB2312">
</head>
<body bgcolor="#FFFFFF">
< p>Only the board owner < %=boardmanager%> can enter this place </p>
<p>Please enter the verification password, and to maintain authentication, please turn on your browser's Cookies. </p>
<form method="post" action="managerloginrest.asp">
<input type="password" name="password">
< input type="hidden" name="boardid"value=< %=boardid%>>
<input type="submit" name="Submit"value="OK">
</form>
Note: This page is only for logging in. After getting the password entered by Mozhu, it cannot perform verification. Instead, the verification work will be carried out on the next page. In fact, the password input and verification work can be completed on one page, but the structural arrangement of the program code is a bit troublesome.
</body>
</html>
< %
set rs=nothing
conn.close
set conn=nothing
%>
Now that the moderator ID and entered password are obtained, the following is the verification work managerloginrest.asp. It accepts the contents of the form in the above file and performs related processing:
< %
response.buffer=true
Note: Set the buffer to allow use. Generally speaking, this item should be added to the header of each ASP page, which can improve the performance of the ASP page. After opening the buffer, there are some corresponding special usages in ASP, which will be mentioned later.
boardid=request("boardid")
password=request("password")
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "driver={Microsoft AccessDriver (*.mdb)};dbq=" & Server.MapPath("bbssystem.mdb")
Set cmd = Server.CreateObject("ADODB.Command")
Set cmd.ActiveConnection = conn
cmd.CommandText = "Moderator password query"
ReDim param(0) 'Declaration
param(0) = CLng(boardid)//Note: CLng cannot be ignored
Set rs = cmd.Execute( ,param)
boardmanager=rs("Board Owner")
if password<>rs("password")then %>
<html>
<head>
<title>Authentication</title>
<meta http-equiv="Content-Type"content="text/html; charset=GB2312">
</head>
<body bgcolor="#FFFFFF">
Incorrect password</body>
</html>
< %
else
session("beenthere")=boarded
Note: Using Session to maintain the identity of the moderator requires that the client browser's cookies be turned on. Because Session is implemented through cookies. Here, assign the board ID to the Session variable beenthere, indicating that the moderator has passed the identity authentication. In each subsequent version processing page, check whether beenthere matches the corresponding version ID.
url="boardmanager.asp?boardid="& boardid
Response.redirect url
supplement: When I first learned ASP, I was always confused by the response.redirect method, and I was unhappy with it. Now let me tell you some techniques. Before using it, you must pass response.buffer=true to let the ASP page use the buffer. At this time, before ASP is interpreted into HTML program code, it is placed in the buffer and is not sent directly to the client browser. Another thing that must be known is: before using response.redirect, no actual HTML program code can be sent to the client browser, otherwise an error will occur. Of course, there are workarounds. If the HTML program code has been interpreted before response.redirect, you can use the response.clear method to clear the buffer, and then use it to reset.
end if
%>
Note: The following is the reset target after the above authentication is passed: boardmanager.asp. It will list all articles that have been processed.
< %
boardid=request("boardid")
if session("beenthere")<>boardidthen response.redirect "forums.asp"
Note: This is where the identity of the moderator is verified, because it has been marked in Bamboo's browser through cookies, and now we can pass seesion Let’s identify the moderator. If the tags do not match, it will return to the original login page through response.redirect. If the moderator's browser cookie is not turned on, the value of seesion ("beenthere") will be empty, and this page will also not be accessible.
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "driver={Microsoft AccessDriver (*.mdb)};dbq=" & Server.MapPath("bbssystem.mdb")
Set cmd = Server.CreateObject("ADODB.Command")
Set cmd.ActiveConnection = conn
sql="select name from board list whereid=" & boardid
set rs=conn.execute(sql)
boardname=rs("name")
cmd.commandtext="Unpublished article list"
ReDim param(0)
param(0) = CLng(boardid)//Note: Clng cannot be ignored
Set rs = cmd.Execute( ,param)
set cmd=nothing
%>
<html>
<head>
<title>Publication processing</title>
<meta http-equiv="Content-Type"content="text/html; charset=GB2312">
</head>
<body bgcolor="#FFFFFF">
< h1 align="center"><%=boardname%>Public management< /h1>
<hr>
< %
if rs.eof or rs.bof then response.write "<H2>There are no articles to process</h2>"
response.end
%>
Note: If no new articles are posted by netizens, this will give a corresponding prompt and use response.end to end the display of this page.
<table width="90%" border="0"cellspacing="0" cellpadding="0"align="center" >
<tr bgcolor="#FFFFCC">
<td width="40%" height="20">Theme</td>
<td width="40%" height="20">Article title</td>
<td width="8%" height="20">Author</td>
<td width="12%" height="20">Date</td>
</tr>
< %
do
topicid=rs("topicid")
articleid=rs("articleid")
data=rs("Date")
datastr=cstr(year(data)) & "-"& cstr(month(data)) &"-"& cstr(day(data))
author=rs("author")
articlename=rs("title")
topicname=rs("topic")
response.write "< tr>< td><a href=qtopic.asp?topicid="& topicid& ">" & topicname &"< /A>< /td>"
response.write "< td>< a href=managearticle.asp?articleid="&articleid & "&boardid="& boardid &">" &articlename & "< /A>< /td>"
response.write "< td>< a href=qauthor.asp?author="&author & ">" & author& "< /a>< /td>"
response.write "< td>" &datastr & "< /td>< /tr>"
rs.movenext
loop until rs.eof
%>
</table>
</html>
< %
set rs=nothing
conn.close
set conn=nothing
%>
</body>
When you click on the link of the corresponding article, you will enter the article processing page managearticle.asp:
< %
articleid=request("articleid")
boardid=request("boardid")
if session("beenthere")<>boardidthen response.redirect "forums.asp"
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "driver={Microsoft AccessDriver (*.mdb)};dbq=" & Server.MapPath("bbssystem.mdb")
Set cmd = Server.CreateObject("ADODB.Command")
Set cmd.ActiveConnection = conn
cmd.CommandText = "Query articles by id"
ReDim param(0)
param(0) = CLng(articleid)//Note: Clng cannot be ignored
Set rs = cmd.Execute( ,param)
author=rs("authorid")
title=rs("title")
data=rs("Date")
rate=rs("recommended degree")
boardid=rs("kanbanid")
topicid=rs("topicid")
boardname=rs("board name")
topicname=rs("topic name")
content=rs("content")
content=replace(content,vbCrlf,"</p><p>")
content="< p>" & content& "< /p>"
set cmd=nothing
%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type"content="text/html; charset=GB2312">
</head>
<Body bgcolor = "#e9e9e4">
<Table width = "89%" border = "0" cellspacing = "0" cellpadding = "0" align = "center">
<Trbgcolor = "#cccccc">
<TD> Author: <font color = "#ff3366" > <a href = "qauthor.asp? Author = < %= author %>" > < %= author %> < /a> < /font> Date: <Font color = "#ff3333"> <%= data%> < /font>
Kanban: <font color = "#ff3333" > <a href = "qboard.asp? Boardid = < %= Boardid %>" > < %= Boardname %> < /a> < /font> Board owner Recommended: <font color = "#ff3333" >#Rate#< /font> < /td>
< /Tr>
<Trbgcolor = "#cccccc">
<TD> Title: <font color = "#ff3333" > <%= Title%>
Subject: <A href = "qtopic.asp? Topicid = <%= Topicid%>" > <%= TopicName%> < /A> < /FONT > < /TD>
< /Tr>
<Tr value = "top">
<TD>
<HR>
<Font color = "#ff3366"> Article content: < /font> <br>
<br>
<Font color = blue> < %response.writeContent %> < /font>
<br>
<HR>
< /Td>
< /Tr>
<Tr value = "top">
<Form Method = "Post" Action = "ManageResult.asp">
<Td height = "18">
<Table width = "100%" border = "1" cellspacing = "1" cellpadding = "1">
<TR>
<Td width = "29%">
G div align = "right">
<Input type = "hidden" name = "boardid" value = "< %= boardid %>">
<Input type = "hidden" name = "topicid" value = "< %= topicid %>">
<Input type = "hidden" name = "articleid" value = "< %= articleid %>">
Article processing: < /div>
< /Td>
<Td width = "12%" borderColor = "#006666"> Delete:
<Input type = "radio" name = "manage" value = 1>
< /Td>
<Td width = "30%" borderColor = "#006666"> Published:
<Input type = "radio" name = "manage" value = 2>
Recommended level <select name = "select">
<Option value = "1"> 1 </option>
<Option value = "2"> 2 </option>
<Option value = "3" select> 3 </option>
<Option value = "4"> 4 </option>
<Option value = "5"> 5 </option>
< /Select>
< /Td>
<Td width = "20%" borderColor = "#006666"> after handling:
<Input type = "radio" name = "manage" value = 3>
< /Td>
<Td width = "9%">
<Input type = "submit" name = "submit" value = "OK">
< /Td>
< /Tr>
< /Table>
< /Td>
< /Form>
< /Tr>
< /Table>
< /Body>
< /Html>
%
set rs=nothing
conn.close
set conn = nothing
%>
Note: This page and articles display the Article.asp in the module is basically the same. It is just added more windows processed by the moderator. I wo n’t talk about it here.
Below, according to the moderator's processing process, repair the corresponding part of the database
< %Response.buffer = TRUE %>
<Html>
<Head>
<Title> Article processing < /Title>
<Meta http-equiv = "content-type" content = "text/html; charset = gb2312">
< /Head>
<Body bgcolor = "#e9e9e4">
%
Articleid = Requst ("Articleid")
boardid = Request ("Boardid")
Topicid = Request ("Topicid")
manage = request ("manage")
'Accept the window content
Response.write Manage 'Show Bamboo ID
if session ("Beenthere") <> boardidthen response.redirect "forums.asp"
Set conn = server.createObject ("Adodb.connection")
conn.open "driver = {microSoft AccessDriver (*.mdb)}; dbq =" & server.mappath ("bbssyStatem.mdb")
According to the operation of the moderator of the previous page, the corresponding treatment below.
if clng (request ("manage") = 1 then
SQL = "Delete from & Articleid
conn.execute sql
Response.write "<H1> The article has been deleted </h1 >"
response.write "<a href => back </a>"
elseif clng (request ("manage") = 2Then
SQL = "Update Content Set set = true whereid =" & articleid
conn.execute sql
SQL = "Update theme table Set article number = number of articles+1Where id =" & topicid
conn.execute sql
Response.write "<H1> The article has published </h1 >"
response.write "<a href => back </a>"
else
response.clear
response.redirect "BoardManager.asp? Boardid =" & Boarded
end if
%>
< /Body>
< /Html>
%
conn.close
set conn = nothing
%>
After a few steps above, even if all parts are basically completed, of course, at this time, it cannot be used, and it cannot be placed on the table. If you want to be able to get it, you need to work hard on the layout, client data verification, etc. But that's all the content of HTML, it doesn't have much to do with ASP, I won't talk about it here.