看上去很美 之asp

來源:互聯網
上載者:User

看上去很美

論壇上有位MM發貼問了一個問題,真是慚愧,我一眼看上去就發現了一個比較明顯的錯誤,估計可能是她的筆誤.我剛回完貼不久,她用訊息跟我聯絡了!錯誤依舊

原貼:

http://topic.csdn.net/u/20080609/13/ab9951e1-6195-4513-a619-b0e304af7c5a.html

先瞞著MM,沒有徵得人家的同意,轉載人家的代碼:)

<% set rst=server.createobject("ADODB.recordset") rst.open "select * from users where u_user='"& request.form("f_user") & "'",conn,1,1 if rst.recordcount>0 then response.write "使用者名稱:"&request("f_user")&"已存在,請擊後退按鈕返回上一頁!" response.end rst.close set rst=nothing conn.close set conn=nothing else rst.open "users",conn,1,3 rst.addnew rst("u_user")=request("f_user") rst("u_code")=request("f_code") rst.update rst.close set rst=nothing conn.clsoe set conn=nothing end if %>

我們一起來分析一下!

1.先用傳過來的使用者名稱查詢是否存在!如果存在就提示,反之就註冊.看上去很美

2.既然存在兩個業務我們就一個一個看.

set rst=server.createobject("ADODB.recordset") rst.open "select * from users where u_user='"& request.form("f_user") & "'",conn,1,1 ' if rst.recordcount>0 then response.write "使用者名稱:"&request("f_user")&"已存在,請擊後退按鈕返回上一頁!" response.end rst.close set rst=nothing conn.close set conn=nothing 

現在假設它只執行一個業務,所以if哪行我注釋掉了,沒有問題我們就繼續看一下業務

 

<% set rst=server.createobject("ADODB.recordset") rst.open "select * from users where u_user='"& request.form("f_user") & "'",conn,1,1 'if rst.recordcount>0 then if 1 <> 1 thenresponse.write "使用者名稱:"&request("f_user")&"已存在,請擊後退按鈕返回上一頁!" response.end rst.close set rst=nothing conn.close set conn=nothing else rst.open "users",conn,1,3 rst.addnew rst("u_user")=request("f_user") rst("u_code")=request("f_code") rst.update rst.close set rst=nothing conn.clsoe set conn=nothing end if %>

注釋掉原來的if判斷,我們用一個類似java的斷言來短路代碼,讓執行流程跳到else塊上執行.如果你看著還不是很清晰的話可以像上面哪樣把它(if哪段代碼)刪掉,像這樣:

<% set rst=server.createobject("ADODB.recordset") rst.open "select * from users where u_user='"& request.form("f_user") & "'",conn,1,1 '此處是刪除的部分佔位rst.open "users",conn,1,3 rst.addnew rst("u_user")=request("f_user") rst("u_code")=request("f_code") rst.update rst.close set rst=nothing conn.clsoe set conn=nothing end if %>

現在,只要稍微寫過點asp的人都能發現一個錯誤了:

rst.open "select * from users where u_user='"& request.form("f_user") & "'",conn,1,1 

rst.open "users",conn,1,3 

這兩行執行完後(或執行不完時),會發生什麼呢?

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.