ASP Quick Start, fast out of the program!

Source: Internet
Author: User
Tags date end include learn php access database
Program | QuickStart I have been working for a year, learned the ASP, PHP, I am a metal heat treatment professional graduate, in the school did not do, and then graduated in the Internet Café one months can not bear to go home self-study ASP, according to the book learned for three months, just reluctantly wrote a chat room program. Later in the company to learn PHP, only in one weeks to get started, the Oriental Self-Help station has a few small errors to fix, but also wrote a simple list of self-help sites. I summed up, the reason why I learned that PHP can have this speed is because I directly contact the program (of course, and the basis of ASP is inseparable), so I think the best way to quickly start ASP is to look at the program.
The most important thing for ASP and HTM is to manipulate the database, so the QuickStart starts with the operational database:
First create a Db1.mdb Access database, a table info, two field IDs (automatic growth), name (character) (the method does not say, and word almost, is very simple).
Establish a database connection, connections/conn0.asp

<%
Dbq=server. MapPath ("./db1.mdb") ' Get database absolute path
constr= "Driver={microsoft Access driver (*.mdb)};d bq=" &AMP;DBQ "Set database connection string
Set Conn=server. CreateObject ("ADODB.") Connection ")" to establish a connection object
Conn.Open constr ' Open connection
%>

Add Data adddata.asp:

<% @LANGUAGE = "VBSCRIPT" codepage= "936"%>
<!--#include file= "connections/conn0.asp"-->
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<title> Add Data </title>
<%
If request. Form ("names") <> "then
Names=server. HTMLEncode (Request. Form ("names")) ' can simply prevent scripting intrusion: <script language= "JavaScript" >while (1) {alert ("^_^")}</script>
Sql= "INSERT into info (name) VALUES (' &names& ')"
' Response. Write (SQL)
Conn.execute SQL
Response. Write ("Add success!") <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>
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
%>

See here you can already write a bulletin system or something; Do you still feel the downside? Oh, how to verify the user landing, what can be done what forum Ah, good below is an example of the operation of cookies and sessions, verify that users to use the session Oh, remember Oh!
Cookie_session.asp

<% @LANGUAGE = "VBSCRIPT" codepage= "936"%>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<title>cookie and Session</title>

<body>
<font color= "#FF0000" >Cookie:</font><br>
<%= request. Cookies ("visit")%>
<%
If request. Cookies ("visit") <> "Then"
Response. Write ("Cap" &request. Cookies ("Visit") & "Secondary Access")
Response. Cookies ("visit") =request. Cookies ("visit") +1
Response. Cookies ("visit"). Expires=date+1
Else
Response. Write ("1th visit")
Response. Cookies ("visit") =1
Response. Cookies ("visit"). Expires=date+1 ' 1 days expired
End If
%><br>

<font color= "#FF0000" >Session:</font><br>
<%
If Len (Session ("visit")) >0 Then
Response. Write ("First" &session ("Visit") & "Secondary Access")
Session ("Visit") =session ("visit") +1
Else
Response. Writ



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.