Use ASP to build a website forum DIY (four)

Source: Internet
Author: User
Tags reset
4, the Forum Management Section

This is the heart of our forum, but it is nothing special to realize. Or those old things: Form processing, database query, in the use of ASP to their organic combination. When entering the article review mode (referred to the Board processing), the most important content, should be the identity of the moderator to verify. below to see moderator landing page:


%
Boardid=request ("Boardid")


(Note: The Boardid is passed through the connection to this page and is the ID of the kanban to be handled by the board.) It is through it to know that the board is dealing with the board. )
Set conn = erver. CreateObject ("ADODB.") Connection ")

Conn. Open "Driver={microsoft accessdriver (*.mdb)};d bq=" & Server.MapPath ("Bbssystem.mdb")
Set cmd = Server.CreateObject ("Adodb.command")
Set cmd. ActiveConnection = conn
Cmd.commandtext = "board Master password Query"
ReDim param (0)
Param (0) = CLng (Boardid)//NOTE: CLng can not be ignored
Set rs = cmd. Execute (, param)
Boardmanager=rs ("board Master")
Set cmd=nothing
%>
html>
head>
title>untitled document
"Meta http-equiv=" Content-type "content=" text/html; charset=gb2312 ">
/head>
Body bgcolor= "#FFFFFF"
p> only the%=boardmanager%> can enter this place.


Please enter a p> password and, in order to remain authenticated, open your browser's cookies.


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 used for landing, it gets the password entered by the moderator, and can not be validated, but the validation of the work on the next page. In fact, the work of password input and validation can be done in one page, but the structure of the program code is a bit cumbersome.


/body>
/html>
%
Set rs=nothing
Conn.close
Set conn=nothing
%>

Now get the moderator ID and entered the password, the following is the work of validation managerloginrest.asp, it accepts the above file form content, and related processing:


%
Response.buffer=true

Note: Set the buffer to allow use. In general, this should be added to the header of each ASP page, which can improve the performance of ASP pages. After opening the buffer, there are some special usages in the ASP, which are mentioned later.


Boardid=request ("Boardid")
Password=request ("password")
Set conn = Server.CreateObject ("ADODB. Connection ")
Conn. Open "Driver={microsoft accessdriver (*.mdb)};d bq=" & Server.MapPath ("Bbssystem.mdb")
Set cmd = Server.CreateObject ("Adodb.command")
Set cmd. ActiveConnection = conn
Cmd.commandtext = "board Master password Query"
ReDim param (0) ' statement
Param (0) = CLng (Boardid)//NOTE: CLng can not be ignored
Set rs = cmd. Execute (, param)
Boardmanager=rs ("board Master")
If password< > RS ("password") then%>
html>
head>
title> Authentication,/title>
"Meta http-equiv=" Content-type "content=" text/html; charset=gb2312 ">
/head>
Body bgcolor= "#FFFFFF"
Bad password
/body>
/html>
%
Else
Session ("Beenthere") =boarded

Note: Use session to maintain authentication to moderators, which requires that the cookie for the client browser be opened. Because the session is implemented through cookies. Here, the Kanban ID is assigned to the session variable Beenthere, indicating that the moderator master has passed the authentication. In each subsequent version of the page, check to see if the Beenthere and the corresponding version ID match.


Url= "boardmanager.asp?boardid=" & Boardid
Response.Redirect URL

Add: Beginner ASP Always for Response.Redirect This method is confused, repeatedly with uncomfortable, now I come to tell you some skills. Before you can use it, you must use the Response.buffer=true to make the ASP page work with buffers. At this point, before the ASP is interpreted as an HTML program code, it is placed in a buffer instead of being sent directly to the client browser. There is also a need to know that before using Response.Redirect, no actual HTML program code can be sent to the client browser, or there will be an error. Of course there are workarounds, if the HTML program code is explained before Response.Redirect, you can use the Response.Clear method to clear the buffer, and then you can use it to reset.


End If
%>

Note: The following is the target of the reset after the authentication is passed: boardmanager.asp. It will list all the articles that have not been processed.


%
Boardid=request ("Boardid")
If session ("Beenthere") >boardidthen Response.Redirect "Forums.asp"

Note: This is the test moderator identity, because the previous cookie in the owner's browser has been marked, now we can through the seesion to identify the moderator. If the mark does not match, it will return to the first landing page via Response.Redirect. If the moderator browser's cookie is not open, then the value of Seesion ("Beenthere") will be empty, also cannot enter this page.


Set conn = Server.CreateObject ("ADODB. Connection ")
Conn. Open "Driver={microsoft accessdriver (*.mdb)};d bq=" & Server.MapPath ("Bbssystem.mdb")
Set cmd = Server.CreateObject ("Adodb.command")
Set cmd. ActiveConnection = conn
Sql= "SELECT name from Kanban list whereid=" & Boardid
Set Rs=conn.execute (SQL)
Boardname=rs ("name")
cmd.commandtext= "List of unpublished articles"
ReDim param (0)
Param (0) = CLng (Boardid)//NOTE: CLng can not be ignored
Set rs = cmd. Execute (, param)
Set cmd=nothing
%>
html>
head>
title> version of the/title>
"Meta http-equiv=" Content-type "content=" text/html; charset=gb2312 ">
/head>
Body bgcolor= "#FFFFFF"
H1 align= "Center" > <%=boardname%> edition Management/h1>
hr>
%
If rs.eof or Rs.bof then Response.Write "Response.End
%>
Note: If no new articles are posted by netizens, this gives the appropriate hints and ends the display of this page with Response.End.
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>
%
Todo
Topicid=rs ("Subject ID")
Articleid=rs ("article ID")
Data=rs ("date")
DATASTR=CSTR (Year (data)) & "-" & CStr (month (data) & "-" & CStr (data)
Author=rs ("author")
Articlename=rs ("title")
Topicname=rs ("Subject")
Response.Write "tr>< td><a href=qtopic.asp?topicid=" & topicid& ">" & Topicname & "/a></td>"
Response.Write "td>< a href=managearticle.asp?articleid=" &articleid & "&boardid=" & Boardid & ">" & Amp;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 the link to the corresponding article is clicked, enter the processing page of this article 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)};d bq=" & Server.MapPath ("Bbssystem.mdb")
Set cmd = Server.CreateObject ("Adodb.command")
Set cmd. ActiveConnection = conn
Cmd.commandtext = "Query article by ID"
ReDim param (0)
Param (0) = CLng (ArticleID)//NOTE: CLng can not be ignored
Set rs = cmd. Execute (, param)
Author=rs ("Author id")
Title=rs ("title")
Data=rs ("date")
Rate=rs ("recommended degree")
Boardid=rs ("Kanban id")
Topicid=rs ("Subject ID")
Boardname=rs ("Kanban name")
Topicname=rs ("Subject 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"
TR bgcolor= "#CCCCCC"
td> Author: Font color= "#FF3366" ><a href= "qauthor.asp?author=<%=author%>" ><%=author%> (/a></font>) Date of publication: "Font color=" #FF 3333 "> <%=data%>/font>
Kanban: Font color= "#FF3333" ><a href= "qboard.asp?boardid=<%=boardid%>" ><%=boardname%></a></font> Board main recommended: "Font color=" # FF3333 "> #rate # </font>/td>
/tr>
TR bgcolor= "#CCCCCC"
td> title: Font color= "#FF3333" > <%=title%>
Subject: "A href=" qtopic.asp?topicid= <%=topicid%> ">%=topicname%></a>/font><
/tr>
TR valign= "Top"
td>
hr>
Font color= "#FF3366" > article content:/font>< br>
br>
Font color=blue><%response.writecontent%></font>
br>
hr>
/td>
/tr>
TR valign= "Top"
Form method= "POST" action= "manageresult.asp"
TD height= "18"
Table width= "100%" border= "1" cellspacing= "1" cellpadding= "1"
tr>
TD Width= "29%"
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>
The TD width= "30%" bordercolor= "#006666" is published:
Input type= "Radio" name= "Manage" value=2>
Recommended Grade
Select Name= "Select"
Option value= "1" >1 </option>
Option value= "2" >2 </option>
Option value= "3" selected>3 </option>
Option value= "4" >4 </option>
Option value= "5" >5 </option>
/select>
/td>
The TD width= "20%" bordercolor= "#006666" to be processed later:
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 the article display module in the article.asp is basically the same, just more than a moderator to deal with the form, here is not much to say.

Below, according to the moderator of the process, repair the corresponding part of the database


%response.buffer=true%>
html>
head>
The title> article deals with the/title>
"Meta http-equiv=" Content-type "content=" text/html; charset=gb2312 ">
/head>
Body bgcolor= "#E9E9E4"
%
Articleid=request ("ArticleID")
Boardid=request ("Boardid")
Topicid=request ("TopicID")
Manage=request ("Manage")
' Accept form Contents
Response.Write Manage ' Display moderator ID
If session ("Beenthere") >boardidthen Response.Redirect "Forums.asp"
Set conn = Server.CreateObject ("ADODB. Connection ")
Conn. Open "Driver={microsoft accessdriver (*.mdb)};d bq=" & Server.MapPath ("Bbssystem.mdb")
According to the actions of the moderator in the previous page, the following processing is appropriate.
If CLng (Request ("Manage")) =1 Then
Sql= "Delete from content table where id=" & ArticleID
Conn.execute SQL
Response.Write "The h1> article has been deleted Response.Write "A Href=>back </a>"
ElseIf CLng (Request ("Manage")) =2then
sql= "Update content table set published =true whereid=" & ArticleID
Conn.execute SQL
sql= "Update topic table Set article number = article number +1where id=" & TopicID
Conn.execute SQL
Response.Write "The h1> article has been published 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, all the parts, even if the basic completed, of course, at this time can not be used, put on the stage. If you want to be able to get out of the words, but also in the layout, client data validation and so on a little more effort. But that is the content of HTML, and ASP not much relationship, here I will not say more.




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.