Use ASP to create an automatic link system

Source: Internet
Author: User
Tags microsoft frontpage

If you have your own website, do you often exchange links with others? Every time you manually add links to others, have you ever thought of an automatic link system that can automatically register website information and generate links? If the answers to these two questions are "yes", please come with me and you will soon get your wish.

An automatic link system should have at least two functions: one is to collect and store website information, and the other is to automatically generate Web Pages Based on stored information. To implement these two functions, simply using the HTML language is obviously not enough. You must use other methods, such as using CGI or ASP for programming.

At present, foreign service providers have provided off-the-shelf CGI programs to automatically generate links. These programs can certainly meet the above two basic requirements, but they have at least two disadvantages: first, slow speed, CGI program itself is not very efficient, coupled with access to foreign sites, the final speed can be imagined. Another point is lack of flexibility. Other people's CGI programs are dead, and there is basically no room for change for users, so they cannot create personalized pages.

ASP (Active Server Pages) technology can make up for the above shortcomings. ASP code is not only flexible, but also faster than CGI programs. Therefore, ASP is a proper choice for website owners.

I. Use

Simple Principle of implementing automatic links in ASP.

1. Information Collection of friendship websites

To collect all kinds of information (including names, website names, addresses, and so on) of a friendship website, we only need to use the standard HTML form technology. A form is placed on the page, with several text boxes and a "Submit" button. The text box is for users to enter information. The action attribute of form is set to the name of the information processing page, that is, the name of the ASP file (autolink in the following example. ASP), the data transmission method is set to post.

2. Saving friendship website information

Autolink. when executing an ASP file, read the parameters using the form attribute of the request object. Then, use the Createobject method of the server object to create an ADO (Active Data Object) object, set the corresponding DNS based on the database type, location, name, and so on, and then use the open method of the ADO object to establish a database connection. After the connection is established, use a standard SQL statement to add a record to the database. For more information about how to embed variables in SQL statements, see the following code ). In this way, information is saved.

3. Generate a link page

To read database information, you must first create a record set Rs using an SQL statement, then read the content of each field using the field attribute of RS, and generate a standard HTML statement based on the field value.

Ii. Instances

The following is a specific instance.

First, we need to create a database to store all the information of friendship websites. In this example, we use access to create a simple database autolink. MDB. The database only contains one table autolink. The table structure is as follows:


Field name


Data Type


Field Length


Required field no


Field description

Name

Character Type

20

Yes

Website name

Address

Character Type

60

Yes

Website address

Logoaddress

Character Type

60

Yes

URL of the Website Logo icon

Description

Character Type

120

Yes

Brief Introduction to the website

Next, we need to create two pages: autolink.htm and autolink. asp.

Autolink.htm is a standard HTML page used to collect information from other websites. Its code is as follows (to save the layout, all modification statements and data integrity check statements are saved in the Code ):

<HTML>

<Head>

<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">

<Title> automatic link system-enter your website information </title>

</Head>

<Form method = "Post" Action = "autolink. asp">

<P> website name: <input type = "text" name = "name"> </P>

<P> website address: <input type = "text" name = "Address"> </P>

<P> icon address: <input type = "text" name = "logoaddress"> </P>

<P> website Description: <textarea rows = "2" name = "Description"> </textarea> </P>

<P> <input type = "Submit" value = "filled in. Submit" name = "Submit"> </P>

</Form>

</Body>

</Html>

The preceding Code creates a form that contains three single-line text boxes, one multi-line text box, and one submit button ), this form is used to receive user input (including website name, address, icon, and description). When a user presses the "Submit" button, the form transmits the user input information to autolink using the POST method. ASP page. Because it is a pure HTML page, we can easily use visual tools such as FrontPage 98 to generate the code.

The code for the autolink. ASP page is as follows (the modifier statement is also omitted ):

<% @ Language = VBScript %>

<HTML>

<Head>

<Meta name = "generator" content = "Microsoft FrontPage 3.0">

<Title> my Links </title>

</Head>

<Body>

<%

Name = request. Form ("name ")

Address = request. Form ("Address ")

Logoaddress = request. Form ("logoaddress ")

Description = request. Form ("Description ")

'Establish a database connection

Set conn = server. Createobject ("ADODB. Connection ")

Mydsn = "driver = {Microsoft Access Driver (*. mdb )};"

Mydsn = mydsn & "DBQ =" & server. mappath ("autolink ")

Conn. Open mydsn

'Add a record

Sqlstring = "insert into autolink (name, address, logoaddress, description) values ("

Sqlstring = sqlstring & "'" & name & "', '" & Address & "', '" & logoaddress & "', '" & Description &"')"

Conn. Execute sqlstring

'Open record set

Sqlstring = "select * From autolink"

Set rs = conn. Execute (sqlstring)

%>

<Table border = "1" width = "72%" cellpadding = "2">

<Tr>

<TD width = "27%"> website name </TD>

<TD width = "73%"> website icons and Links </TD>

</Tr>

<% Do while not Rs. EOF %>

<Tr>

<TD width = "27%"> <% = RS ("name") %> </TD>

& Lt; TD width = "73%" & gt;

<A href = "<% = RS (" Address ") %>">

"> </a> </TD>

</Tr>

<%

Rs. movenext

Loop

%>

</Table>

'Close the connection

<%

Set rs = nothing

Conn. Close

Set conn = nothing

%>

</Body>

</Html>

Upload two files and data warehouse files to the server, and open autolink.htm with a browser, as shown in the figure.

After entering the information, press the "Submit" button to display the picture on the right, indicating that the data has been correctly recorded and the correct HTML page has been generated.

For the example in this article, you only need to make a slight modification to apply it to the actual situation.

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.