How can I use a database to create a multi-user version counter?

Source: Internet
Author: User

Count. asp

'Core counter Program.

<%
Set conn = Server. CreateObject ("ADODB. Connection ")
Dbpath = server. MapPath ("count. mdb ")
Conn. open "driver = {Microsoft Access Driver (*. mdb)}; dbq =" & DbPath
User = Request. QueryString ("user ")

SQL = "update counttable set curvalue = curvalue + 1 where user = '" & user &"'"

'Count value plus1.
Conn. Execute SQL
SQL = "select curvalue from counttable where user = '" & user &"'"
Set rs = conn. Execute (SQL)

Function chgimg (curvalue)
Dim s, I, g
S = cstr (curvalue)
For I = 1 to len (s)

'DefinitionChgimgFunction,Graphically represent the Count value.

G = g & "

'When using the counter,The image path must use the actual path.

Next
Chgimg = g
End function

Toimg = chgimg (rs ("curvalue "))
Toimg = "document. write (" & "'" & toimg &"')"

'CallChgimgFunction incoming counter value.


Response. Write (toimg)

'Output.
Rs. close
Set rs = nothing
Conn. Close
Set conn = nothing
%>

 

Get.htm

'Application Form.
<Form method = "POST" action = "getcl. asp">
<P>User Name<Input type = "text" name = "user" size = "20"> </p>
<P>Counter Initial Value<Input type = "text" name = "curvalue" size = "20"> </p>
<P>Home address<Input type = "text" name = "pageurl" size = "20"> </p>
<P> <input type = "submit" value ="Submit"Name =" B1 "> <input type =" reset "value ="Rewrite"Name =" B2 "> </p>
</Form>

Getcl. asp

'Form for processing user input,And join the database.
<%
Set conn = Server. CreateObject ("ADODB. Connection ")

'Establish a connection with the database.
Dbpath = server. MapPath ("count. mdb ")

'Obtain the actual path of the database.
Conn. open "driver = {Microsoft Access Driver (*. mdb)}; dbq =" & DbPath
Set rs = server. CreateObject ("adodb. recordset ")

User = Request. Form ("user ")
Pageurl = Request. Form ("pageurl ")
Curvalue = Request. Form ("curvalue ")

'Obtain user information.

SQL = "select * from counttable where user = '" & user &"'"

'Check whether the user name exists.
Rs. Open SQL, conn, 1, 3
If not rs. EOF then
Response. Write "<title>Application error</Title>"
Response. Write"Oh,The user name already exists.!Please reselect... </Title>"

Response. End

'Stop downstream processing,Users are required to refill.
End if

Rs. AddNew
Rs ("user") = user
Rs ("pageurl") = pageurl
Rs ("curvalue") = curvalue
Rs. Update

' Add User information to the database .
Rs. Close
Set rs = nothing
Conn. Close
Set conn = nothing
%>


[1]

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.