1 hour ASP entry, very simple

xiaoxiao2021-03-06  27

A.SP common statement

<1> Specification statement

<%

Statement

......

%>

<2> Define Variables DIM statement

<%

Dim a, b

A = 10

B = "ok!"

%>

Note: The defined variables can be numeric types, or other types of characters or other types.

<3> Simple Control Process Statement

IF condition 1 THEN

Statement 1

Elseif Conditions 2 THEN

Statement 2

Else

Statement 3

ENDIF

2.While condition

Statement

Wend

3.for count = 1 to n step m

Statement 1

EXIT for

Statement 2

NEXT

Second .aSP database simple operation tutorial

<1>. Database connection (used to separate connection file conn.asp)

<%

Set conn = server.createObject ("adoDb.connection")

Conn.open "Driver = {Microsoft Access Driver (* .mdb)}; dbq =" & Server.mappath ("/ bbs / db1 / user.mdb)

%>

(Used to connect USER.MDB database under BBS / DB1 / directory)

<2> Display Database Record

Principle: Display the record in the database to the client browser, read out each record in the database

If it is from the end to the end: use the loop and judge whether the pointer is used to use: Not r ..

If it is from the tail to the head: use the loop and judge whether the pointer is started using: NOT RS.BOF

(including conn.asp User.mdb database under BBS / DB1 / directory)

<%

SET RS = Server.createObject ("AdoDb.Recordset") (create a Recordset object)

SQLSTR = "Select * from message" ----> (Message is a data sheet in the database, that is, the data stored by the data you want to display)

RS.Open SQLSTR, CONN, 1, 3 ----> (indicating how to open the database)

rs.Movefirst ----> (will move the needle to the first record)

While Not Rs.eOf ----> (Judge whether the pointer is at the end)

Response.write (RS ("Name")) ----> (Displays the Name field in the data table message)

rs.movenext ----> (move the pointer to the next record)

Wend ----> (End of the loop)

-------------------------------------------------- ----

Rs.close

Conn.close This sentence is used to close the database

SET RS = Nothing

Set conn = Nothing

-------------------------------------------------- -----

%>

Where the Response object is the information sent to the client browser to the client browser

<3> Added Database Record

Add database records to rs.addnew, rs.Update two functions

(including conn.asp User.mdb database under BBS / DB1 / directory)

<%

SET RS = Server.createObject ("AdoDb.Recordset") (create a Recordset object)

SQLSTR = "Select * from message" ----> (Message is a data sheet in the database, that is, the data stored by the data you want to display) rs.open sqlstr, conn, 1, 3 ----> (Indicating how to open the database)

Rs.AddNew adds a record

RS ("Name") = "xx" passes the value of the XX to the Name field

Rs.Update Refresh Database

-------------------------------------------------- ----

Rs.close

Conn.close This sentence is used to close the database

SET RS = Nothing

Set conn = Nothing

-------------------------------------------------- -----

%>

<4> Delete a record

Delete database records mainly use rs.delete, rs.Update

(including conn.asp User.mdb database under BBS / DB1 / directory)

<%

DIM Name

Name = "xx"

SET RS = Server.createObject ("AdoDb.Recordset") (create a Recordset object)

SQLSTR = "Select * from message" ----> (Message is a data sheet in the database, that is, the data stored by the data you want to display)

RS.Open SQLSTR, CONN, 1, 3 ----> (indicating how to open the database)

-------------------------------------------------- -----

While Not Rs.eof

IF RS. ("Name") = Name Then

Rs.delete

rs.Update query is the value of the Name field in the data table is equal to the value "XX" of the variable Name, and if you meet, you will be deleted.

Otherwise, continue to query until the pointer is until the end

rs.movenext

EMD IF

Wend

-------------------------------------------------- ----

-------------------------------------------------- ----

Rs.close

Conn.close This sentence is used to close the database

SET RS = Nothing

Set conn = Nothing

-------------------------------------------------- -----

%>

<5> Query about the 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 "x" "detects whether the user value and the pass value are empty, you can detect a space)

Response.write ("Registration Information cannot be empty")

Elseset RS = Server.createObject ("AdoDb.Recordset")

SQLSTR = "Select * from user where user = '" & user "(querying the user field in the user data table where the user field is characterized)

Rs.open SQLSTR, CONN, 1, 3

IF r.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 ("Register Success")

END IF

Rs.close

Conn.close

SET RS = Nothing

Set conn = Nothing

Response.write ("Registered Repetition")

%>

(b) Query field is digital

<%

DIM NUM

Num = Request.form ("NUM")

SET RS = Server.createObject ("AdoDb.Recordset")

SQLSTR = "Select * from message where id =" & num (Query if the value of the ID field in the Message data table is equal to NUM, where ID is digital)

Rs.open SQLSTR, CONN, 1, 3

IF not r.

Rs.delete

Rs.Update

Rs.close

Conn.close

SET RS = Nothing

Set conn = Nothing

Response.write ("Delete Success")

END IF

Rs.close

Conn.close

SET RS = Nothing

Set conn = Nothing

Response.write ("Delete Fail")

%>

<6> Trist of several simple ASP objects

Response object: The server side sends the information object to the client, including direct sending information to the browser, reordering the URL, or sets the cookie value.

Request object: Request for clients to the server

SESSION object: as a global variable, take effect throughout the site

Server object: Provide access to methods and properties on the server

(a) General usage of response objects

such as:

<%

Resposne.write ("Hello, Welcome to ASP!")

%>

Will you see Hello, Welcome to ASP! This paragraph text in the client browser

<%

Response.Redirect ("www.sohu.com")

%>

If this segment is executed, the browser will automatically connect to the URL of Sohu.

There are still a lot about the usage of the response object, you can study research

General usage method for request object

For example, the client proposed to the server is passed through the Request object.

Such as: The personal information you filled in the mailbox will pass the object.

The information you fill in is passed to the server

For example: This is a form of a form, this is to fill in the information to the customer, fill in the completion

"Submit" is passed to the Request.asp file Processing and then stores the server database

So how to read the information in it, it is necessary to use it here.

Request object, let's analyze the write method of Request.asp

<%

DIM Name, Password (define two variables of user and 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 read the data in the form, and then we have to do will

The information is written to the database, and the way to write the database is introduced, and it will be repeated here.

(Through the above learning, you can do a message version of yourself.)

转载请注明原文地址:https://www.9cbs.com/read-81518.html

New Post(0)