當前位置:旅游攻略大全網 - 旅游景点 - 求ASP簡單源碼!

求ASP簡單源碼!

超簡單的代碼,適合入門的時候用,***6個文件,其中data.mdb是數據庫文件,enter.htm是登陸界面,ent_submit.asp是判斷能否成功登陸的文件,login.asp是登陸成功後跳轉到的頁面,register.htm是註冊會員的界面,reg_submit.asp是處理註冊信息的文件。

1.enter.htm文件

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<title>無標題文檔</title>

</head>

<body>

<form name="form1" method="post" action="ent_submit.asp">

<p> </p>

<p>用戶名:

<input name="username" type="text" id="username" size="20">

</p>

<p>密 碼:

<input name="password" type="password" id="password" size="16">

</p>

<p>

<input type="submit" name="Submit" value="登陸">

<a href="register.htm">註冊為會員</a></p>

</form>

</body>

</html>

2.ent_submit.asp文件

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<title>無標題文檔</title>

</head>

<body>

<%

set conn=server.createobject("adodb.connection")

conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("data.mdb")

username=request.form("username")

password=request.form("password")

sql="select * from user where username='"+username+"' and password='"+password+"'"

set rs=server.CreateObject("adodb.recordset")

rs.open sql,conn,1,3

if rs.eof then

response.Write("<script>alert('用戶名或密碼錯誤,請重新輸入!');history.back(-1)</script>")

else

response.Write("<script>alert('登錄成功!');history.back(-1)</script>")

response.redirect"login.asp"

end if

rs.close

set rs=nothing

conn.close

set conn=nothing

%>

</body>

</html>

3.login.asp文件

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<title>無標題文檔</title>

<style type="text/css">

<!--

.style1 {

font-size: 18px;

font-weight: bold;

}

-->

</style>

</head>

<body>

<div align="center">

<p> </p>

<p> </p>

<p> </p>

<p> </p>

<p class="style1">成功登錄轉到該頁面</p>

</div>

</body>

</html>

4.register.htm文件

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<title>無標題文檔</title>

<style type="text/css">

<!--

.style1 {font-size: 14px}

-->

</style>

</head>

<body class="style1">

<form name="form1" method="post" action="reg_submit.asp">

<p> </p>

<p>用戶名:

<input name="username" type="text" id="username" size="20">

</p>

<p>密 碼:

<input name="password" type="password" id="password" size="16">

</p>

<p>

<input type="submit" name="Submit" value="註冊">

<a href="enter.htm">返回登錄頁面</a></p>

</form>

</body>

</html>

5.reg_submit.asp文件

<%

set conn=server.createobject("adodb.connection")

conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("data.mdb")

username=request.form("username")

password=request.form("password")

exec="select * from user where username='"&username&"'"

set rs=server.createobject("adodb.recordset")

rs.open exec,conn,1,1

if username="" or password="" then

response.Write("<script>alert('用戶名或密碼不能為空!');history.back()</script>")

else

if not rs.eof then

response.Write("<script>alert('對不起,該帳號已有人註冊了,請重新輸入!');history.back() </script>")

else

sql="insert into user(username,password) values('"+username+"','"+password+"')"

conn.execute sql

response.write("<script>alert('註冊成功!');history.back()</script>")

end if

end if

rs.close

set rs=nothing

conn.close

set conn=nothing

%>

6.data.mdb文件

這個需要妳自己建立壹個名為data.mdb的ACCESS數據庫,沒有安ACCESS的需要先安裝好,然後在data.mdb裏面再建立壹個名為USER的表,表字段如下:

id:自動編號

username:文本型

password:文本型