新微赢技术网

标题: 共同学习asp (简单的人员管理) [打印本页]

作者: 街头浪者    时间: 2010-1-8 06:52
标题: 共同学习asp (简单的人员管理)
db
<%
dim db,strCon
strCon="Dbq="&Server.MapPath("db.mdb")&";Driver={Microsoft Access Driver (*.mdb)}"
Set db=Server.CreateObject("ADODB.Connection")
db.Open strCon
%>

add
<!--#include file="db.asp"-->
<%
On Error Resume Next
If Trim(Request("name"))="" Or Trim(Request("password"))=""Then
Response.Write "对不起,姓名和密码必须输入"
Response.Write "<p><a href='add_form.htm'>返回,重新填写</a>"
Else
Dim name,password,tel,email,home,age,intro
name=Request("name")
password=Request("password")
tel=Request("tel")
home=Request("home")
email=Request("email")
age=Request("age")
intro=Request("intro")
Dim strSql,sqla,sqlb
sqla = "Insert Into user(name,password"
sqlb = "Values('" & name & "','" & password & "'"
If tel<>"" Then
sqla = sqla & ",tel"
sqlb = sqlb & ",'" & tel & "'"
End If
If home<>"" Then
sqla = sqla & ",home"
sqlb = sqlb & ",'" & home & "'"
End If
If email<>"" Then
sqla = sqla & ",email"
sqlb = sqlb & ",'" & email & "'"
End If
If age<>"" Then
sqla = sqla & ",age"
sqlb = sqlb & ",'" & age & "'"
End If
If intro<>"" Then
sqla = sqla & ",intro"
sqlb = sqlb & ",'" & intro & "'"
End If
strSql = sqla & ") " & sqlb & ")"
db.Execute(strSql)
If db.Errors.Count>0 Then
Response.Write "保存过程中发生错误,必须重新填写"
Response.Write "<p><a href='add_form.htm'>返回,重新填写</a>"
Else
Response.Write "<h2 align='center'>您的信息已经安全加入,请牢记密码</h2>"
Response.Write "<p>姓名:" & name
Response.Write "<p>电话:" & tel
Response.Write "<p>email:" & email
Response.Write "<p>住址:" & home
Response.Write "<p>年龄:" & age
Response.Write "<p>简介:" & intro
Response.Write "<p><a href='add_form.htm'>返回,继续添加</a>"
End If
End If
%>
del
<%
If Trim(Request("name"))<>"" And Trim(Request("password"))<>"" Then

Dim strSql
strSql ="Delete From user Where name='" & Request("name") & "' And password='" & Request("password") & "'"
Dim number
db.Execute strSql,number
If number=0 Then
Response.Write "姓名或密码输入错误,找不到记录"
Else
Response.Write "<p align='center'>共有" & number & "条数据被删除"
End If
End If
%>
xianshi
<%
Dim rs,strSql
Set rs=Server.CreateObject("ADODB.Recordset")
strSql ="Select * From user Order By name "
rs.Open strSql,db,1

If rs.Bof Or rs.Eof Then
Response.Write "现在还没有数据"
Else
Do While Not rs.Eof '循环直到当前页结束或文件结尾

'下面将利用表格输出名单
Response.Write "<tr bgcolor='#E6E6E6' align='center'>"
Response.Write "<td>" & rs("name") & "</td>"
Response.Write "<td>" & rs("tel") & " </td>"
Response.Write "<td><a href='mailto:" & rs("email") & "'>" & rs("email") & "</td>"
Response.Write "<td>" & rs("home") & "</td>"
Response.Write "<td>" & rs("age") & "</td>"
Response.Write "<td>" & rs("intro") & "</td>"
Response.Write "</tr>"
rs.MoveNext
Loop
End If
rs.Close
Set rs=nothing
db.Close
Set db=nothing
%>
update
<%
'如果没有输入姓名,就不执行下列语句
If Trim(Request("name"))<>"" Then
Dim rs,strSql
strSql ="Select * From user Where name='" & Request("name") & "' And password='" & Request("password") & "'"
Set rs=db.Execute(strSql)
'查找匹配的记录,如果非空,就表示找到了。则引导至update_form.asp
If Not rs.Bof And Not rs.Eof Then
'这里用Session传递记录的id号,而不是在文件后跟参数,是为了安全考虑
Session("id")=rs("id")
Response.Redirect "update_form.asp"
Else
Response.Write "对不起,密码不正确,请重新输入"
End If
End If
%>
update_form
<%
Dim rs,strSql
'根据change.asp存放到Session里的id值,显示相应成员的信息
strSql ="Select * From user Where id=" & Session("id") 'id是数值,就不要加引号了
Set rs=db.Execute(strSql)
%>
<center>
<form method="post" action="update.asp">
<table border="0" width="80%" bgcolor="#E6E6E6">
<tr>
<td>姓名:</td><td><input type="text" name="name" size="20"
value="<%=rs("name")%>">**</td>
</tr><tr>
<tr>
<td>密码:</td><td><input type="password" name="password" size="20"
value="<%=rs("password")%>">**</td>
</tr><tr>
<td>电话:</td><td><input type="text" name="tel" size="20"
value="<%=rs("tel")%>"></td>
</tr><tr>
<td>email:</td><td><input type="text" name="email" size="40"
value="<%=rs("email")%>"></td>
</tr></tr>
<td>住址:</td><td><input type="text" name="home" size="40"
value="<%=rs("home")%>"></td>
</tr></tr>
<td>年龄:</td><td><input type="text" name="age" size="10"
value="<%=rs("age")%>"></td>
</tr><tr>
<td>简介:</td><td><textarea name="intro" rows="2" cols="40"
wrap="soft"><%=rs("intro")%></textarea></td>
</tr><tr>
<td></td><td><input type="submit" value=" 确 定 ">
<input type="reset" value=" 重 填 "> </td>
</tr>
<table>
</form>
</center>
<%
rs.Close
Set rs=nothing
db.Close
Set db=nothing
%>

<%
On Error Resume Next
If Trim(Request("name"))="" Or Trim(Request("password"))=""Then
Response.Write "对不起,姓名、密码必须输入"
Response.Write "<p><a href='update_form.asp'>返回,重新修改</a>"
Else
Dim name,password,tel,email,home,age,intro
name=Request("name")
password=Request("password")
tel=Request("tel")
home=Request("home")
email=Request("email")
age=Request("age")
intro=Request("intro")
'先将原有数据清除,再插入新的数据,为了安全,使用事务处理
db.BeginTrans '开始事务处理
Dim strSql
strSql="Delete From user Where id =" & Session("id")
db.Execute(strSql)
'再将数据填入数据库中
Dim sqla,sqlb
sqla = "Insert Into user(name,password"
sqlb = "Values('" & name & "','" & password & "'"
If tel<>"" Then
sqla = sqla & ",tel"
sqlb = sqlb & ",'" & tel & "'"
End If
If home<>"" Then
sqla = sqla & ",home"
sqlb = sqlb & ",'" & home & "'"
End If
If email<>"" Then
sqla = sqla & ",email"
sqlb = sqlb & ",'" & email & "'"
End If
If age<>"" Then
sqla = sqla & ",age"
sqlb = sqlb & "," & cInt(age)
End If
If intro<>"" Then
sqla = sqla & ",intro"
sqlb = sqlb & ",'" & intro & "'"
End If
strSql = sqla & ") " & sqlb & ")"
db.Execute(strSql)
If db.Errors.Count>0 Then
db.RollbackTrans '如有错误,取消事务处理结果
Response.Write "保存过程中发生错误,必须重新修改"
Response.Write "<p><a href='change.asp'>返回,重新修改</a>"
Else
db.CommitTrans '如无错误,提交事务处理结果
Response.Write "<h2 align='center'>您的信息已经安全修改,请牢记密码</h2>"
Response.Write "<p>姓名:" & name
Response.Write "<p>电话:" & tel
Response.Write "<p>email:" & email
Response.Write "<p>住址:" & home
Response.Write "<p>年龄:" & age
Response.Write "<p>简介:" & intro
Response.Write "<p><a href='change.asp'>返回,继续修改</a>"
End If
End If
%>
作者: 小猫钓鱼tp    时间: 2010-1-8 06:52

作者: 藍麥可兒    时间: 2010-1-8 06:52
学习!
作者: 追梦人︶ㄣ    时间: 2010-1-8 06:52
哈哈,不错,不过好象中间少了些符号吧!
作者: ※随风飘荡※    时间: 2010-1-8 06:52

作者: SJPP    时间: 2010-1-27 06:05
感人肺腑!感人落泪.i服了u!




欢迎光临 新微赢技术网 (http://bbs.weiying.cn/) Powered by Discuz! X3.2