<1> Basic framework
<%
Sentence
Nympho
%>
<2> Define variables DIM statements
<%
dim a, b
a = 10
b = ok!
%>
Note: The defined variable can be numerical, character or other types
<3> Simple control process statement
1. IF condition 1 the
Statement 1
Elseif condition 2 then
Statement 2
else
Statement 3
endif
2.While conditions
Sentence
wend
3.FOR Count = 1 to N Step M
Statement 1
exit for
Statement 2
next
2. ASP Database Simple*Tutorial
<1>. Database connection (used to compile the connection file Conn.asp)
<%
Set conn = server.createObject (adodb.connection)
conn.open driver = {microSoft Access Driver (*.mdb)}; dbq = & server.mappath (/bbs/db1/user.mdb)
%>
(User.mdb database in BBS/DB1/Directory)
<2> Show the database record
Principle: Display records in the database one by one to the client browser, and read out each record in the database in turn
If it is from beginning to end: use the cycle and determine whether the pointer is used to the end: not rs.eof
If it is from the end to the beginning: use the cycle and determine whether the pointer is started to use: not rs.bof
<!-#Include file = conn.asp->
<%
set rs = server.createObject (Adodb.oldSet)
SQLSTR = Select * From Message ----> (MESSAGE is a data table in the database, that is, the data table stored by the data you want to display)
RS.Oopen SQLSTR, Conn, 1,3 -------- (indicate how to open the database)
rs.movefirst -----> (Move the pointer to the first record)
While Not RS.EOF ------>
Response.write (RS (name)) -----> (display the name field in the data table message)
rs.movenext -----> (Move the pointer to the next record)
wend ----> (End of the cycle)
RS.Close
Conn.close these sentences are used to close the database
set rs = Nothing
set conn = nothing
%>
The Response object is the information sent by the server to the client browser.
<3> Add database records
Add database recording: two functions: RS.Addnew, RS.UPDATE
<!-#Include file = conn.asp->
<%
set rs = server.createObject (Adodb.oldSet)
SQLSTR = Select * From Message ----> (MESSAGE is a data table in the database, that is, the data table stored by the data you want to display)
RS.Oopen SQLSTR, Conn, 1,3 -------- (indicate how to open the database)
RS.Addnew adds a new record
RS (name) = xx to the value of XX to the name field
RS.UPDATE refresh the database
RS.Close
Conn.close these sentences are used to close the database
set rs = Nothing
set conn = nothing
%>
<4> Delete a record
Delete database records mainly use RS.DELETE, RS.UPDATE
<!-#Include file = conn.asp->
<%
dim name
name = xx
set rs = server.createObject (Adodb.oldSet)
SQLSTR = Select * From Message ----> (MESSAGE is a data table in the database, that is, the data table stored by the data you want to display)
RS.Oopen SQLSTR, Conn, 1,3 -------- (indicate how to open the database)
While Not RS.EOF
if rs. (name) = name then
rs.delete
The value of the name field in the RS.UPDATE query data table is equal to the value of the variable name XX. If it meets, execute
else, continue to check until the pointer until the end
rs.movenext
emd if
wend
RS.Close
Conn.close these sentences are used to close the database
set rs = Nothing
set conn = nothing
%>
<5> Quhere inquiries about databases
(A) The query field is character type
<%
DIM User, PASS, QQ, Mail, Message
user = request.form (user)
pass = request.form (pass)
QQ = request.form (QQ)
mail = request.form (mail)
Message = request.Form (Message)
if trim (user) & x = x or trim (pass) & x = x then (to detect whether the user value and pass value are empty, you can detect the space)
response.write (registration information cannot be empty)
else
set rs = server.createObject (Adodb.oldSet)
sqlstr = select * from user where user = '' '' '' & user & '' ''
RS.Oopen SQLSTR, Conn, 1,3
if rs.eof then
rs.addnew
rs (user) = user
rs (pass) = pass
rs (QQ) = QQ
RS (Mail) = Mail
RS (Message) = Message
rs.update
RS.Close
conn.close
set rs = Nothing
set conn = nothing
response.write (successful registration)
end if
RS.Close
conn.close
set rs = Nothing
set conn = nothing
response.write (registering heavy name)
%>
(b) The query field is the digital type
<%
dim num
num = request.form (num)
set rs = server.createObject (Adodb.oldSet)
sqlStr = select * From Message Where ID = & Num
RS.Oopen SQLSTR, Conn, 1,3
if not rs.eof then
rs.delete
rs.update
RS.Close
conn.close
set rs = Nothing
set conn = nothing
response.write (successful deletion)
end if
RS.Close
conn.close
set rs = Nothing
set conn = nothing
Response.write (Failure to Delete)
%>
<6> A few simple ASP object explanations
Response object: The information object sent by the server to the client includes directly sending information to the browser, re -directional URL, or setting the cookie value
Request object: the client's request made from the server
Session object: As a global variable, it takes effect at the entire site
Server object: Provide access to the method and attributes on the server
(A) General use of the response object
for example:
<%
resposne.write (Hello, Welcome to Asp!)
%>
You can see Hello, Welcom to Asp! This paragraph of text on the client browser
<%
response.redirect (www.sohu.com)
%>
If this section is executed, the browser will automatically connect to Sohu's website
There are still many usage to the use of the response object. You can study and study
The general use of the Request object
For example, the request made from the client to the server is passed through the Request object
Line Ru: The personal information you filled in the mailbox is to use this object to
The information you filled in is passed to the server
For example: This is the code of a form, which is provided to the customer to fill in the information.
Submit to the server database after submitting to the request.asp file processing
<FORM NAME = FORM1 Method = Post Action = Request.asp>
<p>
<input type = text name = user>
</p>
<p>
<input type = text name = pass>
</p>
<p>
<input type = submit name = submit value = Submit>
</p>
</form>
So how to read the information in the request.asp, write it into the database, and use it here to use it here
Request object, let's analyze the writing of request.asp
<%
DIM NAME, PASSWORD
name = request.form (user) (pass the user information in the form to the variable name)
password = request.form (pass) (pass the pass information in the form to variable password)
%>
Through the above code, we will read the data in the form. What we have to do next is to do it.
The information is written into the database, and the method of writing into the database is introduced. It will not be repeated here.