发新话题
打印

代码已完成了大部分了 就是实现不了我说的那个自减1

代码已完成了大部分了 就是实现不了我说的那个自减1

<!--#include file=cn.asp-->
<%
dim username,userid       
username=replace(trim(request.form("txtname")),"'","")        '定义变量来接受表单的信息
userid=replace(trim(request.form("txtid")),"'","")        '定义变量来接受表单的信息

sql="delete from userlogin where id=" & userid &"  and username='" & username & "'"
cn.execute sql

cn.close
'Response.Write "成功"

dim fso
set fso=server.CreateObject("scripting.filesystemobject")    '执行文件的操作
set ts=fso.OpenTextFile( server.MapPath ("1.ini"),1)
dim x

while not  ts.AtEndOfStream                                '把文件的内容读出 并赋给一个数组变量X
x=x & ts.readline & "*"
wend
ts.close

a=split(x,"*")

for i=0 to ubound(a)-1                                        '用循环去判断是否有这个名字 有 就清空
        if instr(a(i),"=")>0 then                        '取有等号的文件内容 有执行
                b=split(a(i),"=")
                        if instr(b(1),"|")>0 then          '取有|号中的内容
                                dim up
                                up=left(b(1),(instr(b(1),"|")-1))
                                        if  up=username and b(0)="[USER" then                ' 判断是否有跟输入的名字一样的有就清除掉                       
                                                a(i+0)=""
                                                a(i+1)=""
                                                a(i+2)=""
                                                a(i+3)=""
                                                a(i+4)=""
                                                a(i+5)=""
                                                a(i+6)=a(i)                '把下一行的文件内容往上移               
                                                exit for                                       
                                        end if
                        end if
        end if
next

for i=0 to ubound(a)-1             '删除用户信息
        if instr(a(i),"=")>0 then
                k=split(a(i),"=")
                if instr(k(1),"|")>0 then
                        dim ks
                        ks=left(k(1),(instr(k(1),"|")-1))
                        if ks=username then
                                a(i+0)=""       
                        end if                                       
                end if
        end if
next
       
set ts=fso.createTextFile( server.MapPath ("1.ini"),2)                        '把执行的结果写入文件中并覆盖原本的内容
        for i=0 to ubound(a)-1
        if a(i)<>"" then
        ts.writeline a(i)
        end if
        next
ts.close

set ts= fso.opentextfile(server.mappath("1.ini"),1)                        '在从文件中1读取所有的内容
        dim k,N,iniop       

        k=0
        N=0
        blo=false        
      set t=fso.createtextfile(server.mappath("2.ini"),true)
      
        while ts.atendofstream<>true
                op= ts.readline
                b=split(op," ")
                If Instr("opa||" & op,"opa||User" ) > 0 and not blo  Then
                        '记录用户原来的数量
                                k=k+1       
                                iniop=iniop &","& k
                                blo=false
                End If        
               
               
                for i=0 to ubound(b)-1            
                        if instr(b(i),"=")>0 then
                                run=split(b(i),"=")
                                        if instr(run(1),"|")>0 and run(0)="User"  then
                                       
                                                run(0)="User" & k
                                                               
                                                b(i)=run(0) & "="& run(1)
                                                               
                                                t.writeline(b(i))
                                               
                                               
                                                                                                                       
                                        end if
                        end if
                next                                       
       
                'response.write b(i)
       
                       
               
               
                                               
        '        for i=0 to ubound(b)-1            
        '                if instr(b(i),"=")>0 then
        '                                run=split(b(i),"=")
        '                                if instr(run(1),"|")>0 then
        '                                        run(0)="User" & k
        '                                        b(i)=run(0) & "="& run(1)
        '                                        t.writeline(b(i))                                                                        
        '                                end if
        '                end if
        '        next
                t.writeline(op)               
        wend
ts.close
t.close
response.write k
response.write iniop
'response.write op

response.end


'set ts=fso.opentextfile(server.mappath("1.ini"),2)
'for i=0 to ubound(b)
'        ts.writeline(op)
'next
'ts.close




set ts=nothing
'server.transfer"del2.asp"  '跳转到指定的页面 可以直接跳转, 而不用在发送请求

%>
<script>

        window.alert("删除数据成功!");
        window.location="login.asp"
</script>
<%'else%>
<script>
//        window.alert("删除数据有误,请重输!");
//        window.location="del.asp"
</script>
<%'end if%>

TOP

将数据写到ini文件件非常不安全,为什么不写到Access中呢。

TOP

while ts.atendofstream<>true
                op= ts.readline
                       
                        If left(op,4)="User"  Then
                                k=k+1
                                b=split(op,"=")
                                t.writeline("User"&k &"=" & b(1))
                        Else
                                t.writeline(op)
                        End if

               ' t.writeline(op)               
        wend

TOP

引用:
原帖由 Nothing 于 2006-6-21 21:38 发表
将数据写到ini文件件非常不安全,为什么不写到Access中呢。
没有办法拉 这是老师说的 只好照做了 呵呵 不过 谢谢了 我已经写出来了 我的逻辑出错了


我把代码全部换掉了

谢谢了 问题解决了

TOP

发新话题