Design Ultra-Simple message book with Dreamweaver MX 2004

Source: Internet
Author: User
Tags empty html tags insert connect one table variables access database dreamweaver
dreamweaver| Design

Beginners are often unable to learn when they are learning ASP. Learning theory is too abstract to understand, practice and can not find a suitable example to analyze the practice, and sometimes find a source program to learn, the function is too complicated, involves too many ASP modules, also comes with a lot of functions, so that beginners confused, In fact, ASP is relatively easy to grasp, today is for this purpose, She made a very simple message board, only the message, delete and reply function, no administrative authority function (webmaster login, modify password, etc.), Judge function (form verification, etc.) and paging function, simple dry refining, Mainly for beginners to master the most important knowledge, is how to crawl the database and how to view, delete, modify the records of the operation, we first from this super simple message board surgery it, this close as long as you can, congratulations, you can step into the future of ASP application ranks! : This tutorial is completed and will be available for download!

First we do preparation work, first do a plan to see what we might do, the so-called good start is half of success, so we do not rush to do, listen to me slowly. In order for everyone to make their own message board, as far as possible to achieve a Web page a functional module, we will do the following six pages:

First, index.asp----home that display message page
Second, conn.asp----Public Web page, each page must include it, is connected to open the database operation.
Third, write.asp and save.asp----are the form pages and save message pages for the post.
Four, del.asp----Delete the message page
V. reply.asp----reply to the current message page

Well, speaking of which we can work, first of all, to do a most important job, is to establish a database, in the future to store the user's message.
1, database name: Guest.mdb
2, database table: Only one table: Book
3. Add the following fields to the book of the datasheet, see Figure 1

Note: • The "Allow empty strings" in the "normal" item in the data type of any field is best filled with "yes"

• The default value of the date/time "regular" item is now (), and the default value in the "normal" entry in the webmaster reply is "No reply", note that double quotes are added here, half corners instead of full-width.

When the database is built, start doing public Web pages to open the database, open Dreamweaver MX 2004, and create a new dynamic ASP page as follows:

and save it as conn.asp, switch to the display code view in the edit area, and note that the first line of automatically generated code is deleted.

This is mainly written to connect the database and parameter settings ASP code, do not output what HTML tags, so the code all deleted, with Dreawmeaver inserted into the column with the ASP object to write the following code, the ASP column does not have the code can only own handwriting input.

Note To put all the ASP code to be compiled between <%%>, so that the normal operation, otherwise there will be errors! This is the basic knowledge oh. Let me explain what the above code means:

Code First line: used to establish connection objects, connection objects play a very important early connection work, connect the successful database will have future data operation function.

Second line of code: Set database connection parameters. Includes a database driver and database file name.

Code Third line: Open the database with the Conn connection object.

These are universal connection database method, any need to open the database Dynamic Web page can be copied above the line, only the database name changed to your database name on the line, note that the path to correct. So you can put this code in the code snippet Dreawmeaver, after the direct insertion can be used, more convenient, without memory, this is a small feat!

New Dynamic Web page index.asp: First in the Design view of the layout of a message board interface, design a good page effect chart as follows:

The following table planning and display are very clear, at a glance, what typesetting I will not say it: it is basic skills, if not the words can be learned first dreamweaver,[if it is a beginner please see dreamweaver video tutorial Ah! Then learn the ASP Oh! Steady play, the wisdom of ^_^. If you want to be lazy, you can download the source code directly, learning to study ASP code can also ah, I do not object to Oh, at least I am so lazy, understand long live! :)

After the layout of the version and then into the code view, in different locations insert the following ASP code: The following figure:

In the top line of the page code, click the symbol circled with the red thread can insert the first line of code, and can be browsed to specific files, more convenient, note that the choice of file type, not virtual type. This inserts the Conn.asp database Connection code page, this code is included in the current page location for normal compilation, do not repeat the database connection code, it has great benefits oh, so that the structure of the page, easy to modify and maintain, if the database connection error, or database file changes, you need to change the conn.asp, you do not have to modify each The code for the page. To be good at this method, it will make your program simple, clear, this is a common programming method.

Then enter the second line to the sixth line of code block, the meaning of this code block let me say:

The third line of code: Since the Web page and the database with connection to establish a connection to open the relationship, then the most important task is to read the data. Set up RS object variables as Recordset objects, so that you can use RS object variables to access database operations later.

Four lines of code: Put the results from the query in the datasheet book onto the SQL variable. It means that all the data in the book is taken out and sorted by ID from big to small. Desc said that from large to small sort, if not added, the latest message but in the end oh, inconvenient.

Line five: Indicates that the RS object variable open method opens the data table book, fetching the results by SQL query method.

 The above is a common way to read records, to other places can be extrapolate, to be familiar with the use!

And then we're going to do a no message recording of the judgment display code out, we want to locate the "no message" the beginning of the form tag code, plus line 28th below the red lines of code can be, this code represents a judgment statement: if the RS record pointer to the EOF end and the beginning of the BOF are empty, return True, execute the following label, Enter the form without a message, and do not output the other tags below. Then navigate to the "no message" form the end of the tab, enter the following 36, 37 lines of code to complete the judgment conditions, Response.End said the output end, no longer output the following code.

Second, if the record is not empty, enter the form of the message, respectively positioned in the output of the message table tags in front and behind, insert the ASP code block the following figure input:

  The meaning of this code block is to point the RS record pointer to the first record, and then start to determine whether the record is null at the end of the move, if not empty, and then move the pointer to read all the data. Exit the loop until the end is empty.

Then we do the most important is also the most frequently used work, is the data table each field records are read out in the form of the two places, example name, QQ, email and message. Before you convert to Design view and code view, see the following figure:

We found a lot more tags on the map, which is the ASP code just entered in the Code view, which is convenient for us to modify in the Design view, the output preview does not affect the typesetting. We position the cursor in the table next to the name, click on the Insert column ASP, automatically inserted in the code area designated location, more convenient, not easy to mistake, the following figure:

Then select the tag next to the name, click the Edit button in the property bar, and enter RS ("name"). <%=%> represents an output variable value, equivalent to a simplified version of Response.Write. RS is the last Recordset object that has been built, you can read the contents of the field directly, name is the Name field in the book in the datasheet.

In the same way, insert the ASP code message content, the Publisher, the publication time and the reply content in different position, respectively:

Message content: <%=server.htmlencode (rs ("content"))%>
Published by: <%= rs ("name")%>
Published: <%= rs ("Time")%>
Webmaster Reply: <%= rs ("Repcontent")%>

You may find that the message content inserted in the code and the other slightly different, more Server.HTMLEncode This object, this is for security purposes, is an HTML-encoded object, you can have HTML tag text is not interpreted as HTML tags, This prevents the malicious person from writing special execution code, causing unnecessary loss.

This is done, as shown in the following illustration:

Then do oicq,email,homepage link settings, and this is not the same as the above, it is not directly show the record can, but will move the mouse to the QICQ on the emergence of the QQ number of the message, click EMAIL automatically to the message that the letter, Click Homepage to get to the website of the message directly.
Select Oicq, plus the "#" empty link, the same also to email and homepage Plus "#" empty links. As shown in the following illustration:

We all know that to the picture to add a hint is simpler, directly in the ALT set text description can be, but the text is not ALT, it doesn't matter, our Dreamweaver has long thought, very powerful Oh! Oicq in the code area of the empty link #, by the space (note that the English input method is effective) will appear smart cue parameters out, we choose "title", and then hit the "<%= rs (" Oicq ")%>" Can!

The same way to email and homepage plus Ah, the method as shown below the red line:

Everything's OK,!!!. ^_^ found that the background of Oicq,email and homepage in Design view turned to light blue, which means that we add ASP code to them on the link, so the different prompts are very considerate:

I'm sure you can't wait to see the effect! But there is no record ah, did not do the message Submission page and reply page, delete the page, had to temporarily in the database manually add records.

It's too late today! Go ahead and write it tomorrow! Oh!

Next page



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.