In the previous we introduced the file version of the guest book, now we may wish to imagine: if the message file inside a lot of messages, and you are eager to find one of the messages, then open a TXT message file, a paragraph of the message record, you can guarantee you will not faint on the spot? And the most annoying file book is far more than just this reason, more irritating is: for example, you have found the message you are looking for, and it is not to delete it (of course, because the message was mercilessly to your face smear reason), then the rest of you want to praise the words of friends, It will be because you are doing a message delete operation and can not leave a message. Look, how bad it is! However, you do not need to sigh, although the message file can not be shared with many people, but changed into a database to manage the message records, when you do delete messages during the period, visitors can add the message. Since the database guest book can be so attentive to your system, we now without further ado, immediately to uncover her true colors.
As for how to build their own database version of the guest book, Shanghai Treatment of impotence hospital procedures or through a step-by way to explain it. To write a database version of the guest book, we can roughly from the following three steps to complete.
Step One: Use Access to set up a data table to hold your message. (Of course, if you want to make your database work well in high-demand, high-quality Web application customer-server databases, and both performance and reliability can withstand rigorous testing, then you'd better use a server-grade database, such as: SQL Server, Oracle, and so on. For non-server grade databases, I recommend using the Chinese version of access to build. All data tables created with access are suffixed with an. mdb, such as: Book0.mdb. )
Access interface is very friendly, easy to operate, I believe that smart readers, even if they have never used access, as long as the hands-on to try, it will be able to quickly rob a crossbow, so I will not repeat this here (of course, but also do not rule out a few lazy ingredients).
Step two: The design of a message form page is also indispensable. (such as: guestbook0.htm).
Step three: To write the processing of the message of the ASP program. (We can copy the following code and save it as a manage0a.asp file.) )
$#@60,!--#include file= "Adovbs.inc"--$#@62;
Call the Adovbs.inc file, the so-called Inc file is the name of the include file, Adovbs.inc is the IIS/PWS provided by the files, storing the definition of ADO related constants, using the Inc file can make our program, increase readability, Easier to develop and maintain.
$#@60; % Function sqlstr (data)
Sqlstr = "" & Replace (Data, "") & ""
End Function
Here, the SQLSTR function is used to change a single quotation mark in the data to two single quotes, plus a single quotation mark around the other. The reason to use this function is that the data entered by the surfer must be combined with the INSERT INTO command in the form of single quotes, but if the data entered by the user contains single quotes, the data entered will produce an error. Therefore, the input data must be switched SQLSTR (the single quotation mark is switched to two single quotes) is correct.
Name = Request ("name")
Tel=request ("Tel")
email = Request ("email")
Subject = Request ("Subject")
Memo = Request ("Memo")
Get the data from the guestbook form
If Name = "or tel=" "or Email =" "or Subject =" "or Memo =" Then Response.Write "the input box cannot be blank!"
Response.End
End If
Check the form's input boxes for information input, if left empty input box does not fill the display description information: "Input box cannot be blank!" and stop executing the following program.
Set conn = Server.CreateObject ("ADODB. Connection ")
Get the object adodb.connection with Server.CreateObject. Because in ASP, if you want to access data must first create a link to the database, so establishing a connection is an indispensable step to access the Web database, after executing the above statement, Conn is a connection object.
DBPath = Server.MapPath ("Book0.mdb")
Get the full path to the Book0.mdb by calling the MapPath method of the server object.
Conn. Open "Driver={microsoft Access driver (*.mdb)};d bq=" & DBPath
Because we want to open an access (. mdb) database, we want to access the database through the ODBC driver {Microsoft access Driver (*.mdb)} in Access, and the DBP parameter is used to specify the database file that you want to open. Because it must be the full path name, we used the Server.MapPath function on the previous statement.
Name = Left (name, 40)
Tel = Left (tel,10)
email = left (email, 80)
Subject = Left (Subject, 127)
Truncate the length of the data entered into each field to avoid errors caused by the extra length of data entered into a field, but if we set the data type of each field in the database Book0.mdb to "Memo", we no longer have to worry about how long the data is entered by the Internet user.
sql = "Insert into guestbook (name, phone, Email, subject, message) Values ("
sql = SQL & Sqlstr (Name) & ","
sql = SQL & Sqlstr (Tel) & ","
sql = SQL & Sqlstr (Email) & ","
sql = SQL & Sqlstr (Subject) & ","
sql = SQL & Sqlstr (Memo) & ")"
Add a data record to the "guestbook" data sheet, and then set each field (name, phone, Email, subject, message) as the corresponding data to be removed from the message form.
Conn. Execute SQL
Executes the SQL instruction.
%$#@62;
ASP Advanced Tutorial Ⅷ: Database version of the guestbook