The application of ASP technology in the Forum (VI.)

Source: Internet
Author: User
Tags error handling html form
The article publishing module has only two pages, one is the submit.asp used to provide input forms, and one is the subresult.asp for processing form input. The front page is very simple, basically is an HTML form, there is nothing to talk about, the following look at the content of subresult.asp:

  

< html>

< head>

< title> published articles </title>

< meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">


< body bgcolor= "#FFFFFF" >

  

<%

Author=request ("author")

Password=request ("password")

Topicid=request ("TopicID")

Boardid=request ("Boardid")

Content=request ("content")

Title=request ("title")

  

This section takes out the table submitted in submit.asp but the contents are placed in the corresponding variable.

  

Set conn = Server.CreateObject ("ADODB. Connection ")

Conn. Open "Driver={microsoft Access driver (*.mdb)};d bq=" & Server.MapPath ("Bbssystem.mdb")

Set cmd = Server.CreateObject ("Adodb.command")

Set cmd. ActiveConnection = conn

  

' Query if the author already exists

Cmd.commandtext = "SELECT * from author table where id= '" & Author & "'"

Set rs = cmd. Execute ()

  

' Check Permissions

If rs.eof or Rs.bof then

Response.Write "< h3> you have not yet registered, please < a href=register.htm> registration </a> later in to publish articles
Response.Write "</body>
Response.End

End If

  

If password< > rs ("password") then

Response.Write "< h2> password error, please check that the password is correct
Response.Write "</body>
Response.End

End If

  

This section is the author's permission to check, for the account does not exist or password error to make the appropriate error handling. Here you can see the usage of Response.End, which is used to end the current ASP script. Combined with an If statement, you can handle the expected errors in the program. In a good Web application, error handling is essential.

  

' Change the single quotation marks in the data to two single quotes and precede them with single quotes

Function sqlstr (data)

Sqlstr = "'" & Replace (data, "'", "" ") &" "

End Function

  

' Write to the database

sql = "Insert into content table (Kanban ID, subject 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> articles have been sent to the database, and when the board is reviewed you can see the < h2>

</body>


Here, the article has been saved in the database. However, it can not be displayed immediately, but also need the approval of the owner to do. Next, take a look at the content of the Management section of the Forum.



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.