Looks beautiful
On the forum, a mm post asked a question. I found a very obvious mistake at a Glance. It may be her mistake. shortly after I posted the post, she contacted me with the message! Error still
Original post:
Http://topic.csdn.net/u/20080609/13/ab9951e1-6195-4513-a619-b0e304af7c5a.html
Without the consent of someone else, I copied the code from someone else :)
<% 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 "username:" & request ("f_user") & "already exists. Please click back to return to the previous page! "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 %>
Let's analyze it together!
1. Check whether the user name already exists! If yes, you will be prompted. Otherwise, you will be registered.
2. Since there are two businesses, let's look at them one by one.
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 "username:" & request ("f_user") & "already exists. Please click back to return to the previous page! "Response. End RST. Close set rst = nothing conn. Close set conn = nothing
Now let's assume that it only executes one business, so I commented out the line if, so let's continue to look at the business.
<% 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 "username:" & request ("f_user") & "already exists. Please click back to return to the previous page! "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 %>
Comment out the original if judgment. We use a Java-like assertion to short-circuit the code and let the execution flow jump to the else block for execution. if you are not very clear about it, You can delete it like the code above (if code), like this:
<% Set rst = server. createobject ("ADODB. recordset ") rst. open "select * from users where u_user = '" & request. form ("f_user") & "'", Conn,' Here is the deleted Part Of The placeholder 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 %>
Now, anyone who writes ASP a little bit can find an error:
RST. Open "select * from users where u_user = '" & request. Form ("f_user") & "'", Conn, 1, 1
RST. Open "users", Conn, 1, 3
What will happen after these two rows are executed (or when they are not completed?