jennypretty
04-24-2007, 05:26 PM
Hello,
I am trying to create a form to insert data in sql server table. I want to check if email address exists or not. If exists, shows errors like "Email exists, try another", if not, insert the form to the db.
Here is my code, but it does nothing.
Is there a better way to check it or what did I do wrong?
thanks.
email_address = trim(fixStr(Request("emailAddress")))
first_name = trim(fixStr(Request("firstName")))
<%
strSQL = "Insert into students(First_name, email_address) values ('" & First_Name & "', '" & Email_Address & "')"
strSQL = "Select * From students Where Email_Address = '" & email_Address & "'"
set pRS = server.CreateObject("ADODB.Recordset")
pRS.open strSQL, Conn,3,1,1
if not(pRS.eof) then
pRS.close
set pRS = nothing
conn.close
set conn=nothing
session("strMsg") = "The Email address existed, try another"
response.redirect "student.asp?FirstName=" & First_Name &" &EmailAddress=" & Email_Address
end if
conn.execute strSQL
%>
I am trying to create a form to insert data in sql server table. I want to check if email address exists or not. If exists, shows errors like "Email exists, try another", if not, insert the form to the db.
Here is my code, but it does nothing.
Is there a better way to check it or what did I do wrong?
thanks.
email_address = trim(fixStr(Request("emailAddress")))
first_name = trim(fixStr(Request("firstName")))
<%
strSQL = "Insert into students(First_name, email_address) values ('" & First_Name & "', '" & Email_Address & "')"
strSQL = "Select * From students Where Email_Address = '" & email_Address & "'"
set pRS = server.CreateObject("ADODB.Recordset")
pRS.open strSQL, Conn,3,1,1
if not(pRS.eof) then
pRS.close
set pRS = nothing
conn.close
set conn=nothing
session("strMsg") = "The Email address existed, try another"
response.redirect "student.asp?FirstName=" & First_Name &" &EmailAddress=" & Email_Address
end if
conn.execute strSQL
%>