(Summary by yourself, please give me some advice)
1. Introduction to VBScript Syntax
VBScript statement is a scripting language based on VB, mainly used for program development on the WEB server side.
Here are only some simple statements, mainly several common statements for operating databases
<1>.vbscript logo
<%
Statement
...
%>
<2>Define variable dim statement
<%
dim a,b
a=10
b=ok!
%>
Note: Note: The defined variables can be numerical, or characters or other types.
<3>Simple control flow statement
1. If condition 1 then
Statement 1
elseif condition 2 then
Statement 2
else
Statement 3
endif
2.while conditions
Statement
wend
3.for count=1 to n step m
Statement 1
exit for
Statement 2
next
2. Simple operation tutorial of asp database
<1>.Database connection (used to compile the connection file conn.asp separately)
<%
Set conn = Server.CreateObject(ADODB.Connection)
conn.Open DRIVER={MicrosoftaccessDriver (*.mdb)}; DBQ= & Server.MapPath(/bbs/db1/user.mdb)
%>
(Used to connect to the user.mdb database under the bbs/db1/ directory)
<2>Display database records
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 loop and determine whether the pointer is used at the end: not rs.eof
If it is from the end to the beginning: use loop and determine whether the pointer is at the beginning: not rs.bof
<!--#include file=conn.asp--> (Contains conn.asp to open the user.mdb database under the bbs/db1/ directory)
<%
set rs=server.CreateObject(adodb.recordset) (create recordset object)
sqlstr=select * from message --->(message is a data table in the database, that is, the data table stored in the data you want to display)
rs.open sqlstr,conn,1,3 ---> (represents the way to open the database)
rs.movefirst --->(Move the pointer to the first record)
while not rs.eof --->(Judge whether the pointer reaches the end)
response.write(rs(name)) --->(Show the name field in the data table message)
rs.movenext --->(Move the pointer to the next record)
wend --->(end of loop)
-------------------------------------------------- ----
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
Adding database records uses two functions rs.addnew and rs.update
<!--#include file=conn.asp--> (Contains conn.asp to open the user.mdb database under the bbs/db1/ directory)
<%
set rs=server.CreateObject(adodb.recordset) (create recordset object)
sqlstr=select * from message --->(message is a data table in the database, that is, the data table stored in the data you want to display)
rs.open sqlstr,conn,1,3 ---> (represents the way to open the database)
rs.addnew Add a new record
rs(name)=xx Pass 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
Deleting database records mainly uses rs.delete, rs.update to delete them
<!--#include file=conn.asp--> (Contains conn.asp to open the user.mdb database under the bbs/db1/ directory)
<%
dim name
name=xx
set rs=server.CreateObject(adodb.recordset) (create recordset object)
sqlstr=select * from message --->(message is a data table in the database, that is, the data table stored in the data you want to display)
rs.open sqlstr,conn,1,3 ---> (represents the way to open the database)
-------------------------------------------------- -----
while not rs.eof
if rs.(name)=name then
rs.delete
rs.update query whether the value of the name field in the data table is equal to the value xx of the variable name. If it matches, it will be deleted.
else Otherwise continue querying until the pointer reaches the end
rs.movenext
end if
wend
-------------------------------------------------- ----
-------------------------------------------------- ----
rs.close
conn.close These sentences are used to close the database
set rs=nothing
set conn=nothing
-------------------------------------------------- -----
%>
<5> Query about database
(a) 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, spaces can be detected)
response.write (Registration information cannot be empty)
else
set rs=server.CreateObject(adodb.recordset)
sqlstr=select * from user where user='&user&' (query the user field in the user data table, where the user field is character type)
rs.open 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(Registered successfully)
end if
rs.close
conn.close
set rs=nothing
set conn=nothing
response.write (register rename)
%>
(b) The query field is numeric
<%
dim num
num=request.Form(num)
set rs=server.CreateObject(adodb.recordset)
sqlstr=select * from message where id=&num (query whether the value of the id field in the message data table is equal to num, where id is numeric)
rs.open 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 (delete successfully)
end if
rs.close
conn.close
set rs=nothing
set conn=nothing
response.write (deletion failed)
%>
<6> Explanation of several simple asp objects
Response object: The information object sent by the server to the client, including sending information directly to the browser, redirecting the URL, or setting the cookie value
request object: The request made by the client to the server
session object: As a global variable, it takes effect throughout the site
Server object: provides access to methods and properties on the server
(a) General usage method of response object
for example:
<%
Response
.write(hello, welcome to asp!)
%>
In the client browser, you will see hello, welcome to asp!
<%
response.Redirect(www.sohu.com)
%>
If this segment is executed, the browser will automatically connect to Sohu's URL
There are many other uses of response objects, you can study them
General usage method of request object
For example, the request request made by the client to the server is passed through the request object.
For example, the personal information you fill in in the application email address is to use the object to
The information you filled in is passed to the server
For example: This is a form code, which is provided to the customer for filling in information. After filling in it, press
Submit and pass it to the request.asp file before processing and then deposit it into the server database
<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 request.asp into it, and write it to the database, you need to use it here
The request object is here. Let’s analyze the writing method of request.asp.
<%
dim name,passWord (defines two variables user and password)
name=request.form(user) (pass user information in the form to the variable name)
password=request.form(pass) (pass the pass information in the form to the variable password)
%>
Through the above few code sentences, we read the data in the form, and the next thing we have to do is to
The information has been written to the database, and the method of writing to the database has been introduced above, so I will not repeat it here.
(Through the above learning, you can make a message version by yourself)