ASP Quick Start, Quick Start program!

Source: Internet
Author: User

I have been working for a year and have learned ASP and PHP. I graduated from the metal material heat treatment major and did not do it at school. I graduated from an Internet cafe for a month and couldn't stand going home to learn ASP by myself, I barely wrote a chat room program after studying the book for three months. Later, I learned PHP in my company. It took only a week to get started. I made several minor mistakes in building a self-help site in Dongfang and wrote a simple self-help site list. I have summarized that the reason why PHP can be learned at this speed is that I directly access the program (of course, it is inseparable from the foundation of ASP ), so I think the best way to get started with ASP is to look at the program.
Compared with htm, ASP is most important in database operations, so the Quick Start is to start with database operations:
First, create the ACCESS database of db1.mdb, a table info, two field IDS (auto-increment), name (character) (the method is not mentioned, it is similar to word, it is very simple ).
Create a database connection, connections/conn0.asp

<%
DBQ = server. mappath ("./db1.mdb") 'obtains the absolute path of the database.
Constr = "driver = {Microsoft Access Driver (*. mdb)}; DBQ =" & DBQ 'set the database connection string
Set conn = server. Createobject ("ADODB. Connection") 'to create a connection object
Conn. Open constr 'open connection
%>

Add data adddata. asp:

<% @ Language = "VBScript" codePage = "936" %>
<! -- # Include file = "Connections/conn0.asp" -->
<HTML>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> add data </title>
</Head>
<%
If request. Form ("names") <> "" then
Names = server. htmlencode (request. form ("names") 'can easily prevent script intrusion: <script language = "JavaScript"> while (1) {alert ("^_^")} </SCRIPT>
SQL = "insert into Info (name) values ('" & names &"')"
'Response. Write (SQL)
Conn.exe cute SQL
Response. Write ("added successfully! <Br> continue <a href = adddata. asp> Add </a> or <a href = showdata0.asp> View </a>. ")
End if
%>
<Body>
<Form name = "form1" method = "Post" Action = "">
<Input name = "names" type = "text" id = "names">
<Input type = "Submit" name = "Submit" value = "add">
</Form>

</Body>
</Html>
View data showdata0.asp
<% @ Language = "VBScript" %>
<! -- # Include file = "Connections/Conn. asp" -->
<%
Dim rs
Dim rs_numrows

Set rs = server. Createobject ("ADODB. recordset ")
Rs. activeconnection = mm_conn_string
Rs. Source = "select * from Info"
Rs. cursortype = 1
Rs. cursorlocation = 2
Rs. locktype = 3
Rs. open ()

'Response. Write ("dim A" & vbcrlf)
'Response. Write ("redim A (" & rc & ")" & vbcrlf)
Outhtml = ""
If not (Rs. EOF and Rs. bof) then
Response. Write ("<script language =" "JavaScript" ">" & vbcrlf)
While not Rs. EOF
Outhtml = outhtml & Rs. Fields. Item ("name"). Value & "<br>"
Rs. movenext
'Response. Write ("A (" & I & ") =" & Rs. Fields. Item ("name"). Value & "& vbcrlf)
Wend
 

Response. Write ("opener. showr. innerhtml =" & outhtml & "" & vbcrlf)

Response. Write ("opener. Sets ()" & vbcrlf)
Response. Write ("window. Close ()" & vbcrlf)
Response. Write ("This. Close ()" & vbcrlf)
Response. Write ("</SCRIPT>" & vbcrlf)
End if
Rs. Close ()
Set rs = nothing
%>

You can write an announcement system or something here. Do you still think there are some shortcomings? Well, how can I verify the user login before I can create any forum? Well, the following is an example of cookie and session operation. Please remember to verify that the user wants to use session!
Cookie_session.asp

<% @ Language = "VBScript" codePage = "936" %>
<HTML>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> cookie and session </title>
</Head>

<Body>
<Font color = "# ff0000"> COOKIE: </font> <br>
<% = Request. Cookies ("visit") %>
<%
If request. Cookies ("visit") <> "" then
Response. Write ("th" & request. Cookies ("visit") & "secondary access ")
Response. Cookies ("visit") = request. Cookies ("visit") + 1
Response. Cookies ("visit"). expires = date + 1
Else
Response. Write ("1st accesses ")
Response. Cookies ("visit") = 1
Response. Cookies ("visit"). expires = date + 1' 1 day expired
End if
%> <Br>

<Font color = "# ff0000"> session: </font> <br>
<%
If Len (Session ("visit")> 0 then
Response. Write ("" & SESSION ("visit") & "")
Session ("visit") = SESSION ("visit") + 1
Else
Response. Write ("1st accesses ")
Session ("visit") = 1
End if
%> <Br>

</Body>
</Html>

Now, if you understand and can write similar things, you will get started!

Conclusion: This article adds a friend who understands HTML and has learned any programming language (JS and vbs) to prepare to learn ASP.
Thank you.

 

My QQ group:

Phper & webgame & mobile development, group number: 95303036

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.