SELECT and INSERT in wrong order
I am using ASP to talk to MYSQL. The following code is suppopsed to checking whether a username/password combination exists. If it does it redirects back to the form. If not it adds the record to the database.
The problem - when the username/password is undoubtedly unique, it is somehow executing the INSERT first and then the SELECT ! Sounds ridiculous but true. Thus the script adds the new record to the database and yet still flags up that it exists. Any ideas why ?!
title=replacequotes(request("title"))
name=replacequotes(request("name"))
surname=replacequotes(request("surname"))
postcode=replacequotes(request("postcode"))
email=replacequotes(request("email"))
position=replacequotes(request("position"))
positiontype=request("positiontype")
hourlyrate=request("hourlyrate")
salary=request("salary")
prefregion=request("prefregion")
prefcounty=request("prefcounty")
industrysector=request("industrysector")
skillsets=replacequotes(request("skillsets"))
requireeupermit=request("requireeupermit")
username=replacequotes(request("username"))
password=replacequotes(request("password"))
set objconn=Server.CreateObject("ADODB.Command")
objconn.ActiveConnection=dbProvider
objconn.CommandType=adCmdText
' first check that username and password are not already being used
sql="SELECT Refno FROM Candidates WHERE username='"&username&"' AND password='"&password&"'"
objconn.CommandText=sql
set objRS=objconn.Execute
if not objRS.EOF then
set objRS=nothing
set objconn=Nothing
response.redirect "register-job-seeker.asp?errorlevel=1"
else
set objRS=nothing
' next free record number then update DB
refno=get_nextfree("candidates")
sql="INSERT INTO Candidates (RefNo,Title,Name,Surname,Postcode,Email,Position, PositionType,Hourlyrate,Salary,Prefregion,Prefcoun ty,Skillsets,RequireEUpermit,industrysector,userna me,password) values ('"&refno&"','"&title&"','"&name&"','"&surname&"', '"&postcode&"','"&email&"','"&position&"','"&posit iontype&"','"&hourlyrate&"','"&salary&"','"&prefre gion&"','"&prefcounty&"','"&skillsets&"','"&requir eeupermit&"','"&industrysector&"','"&username&"',' "&password&"')"
objconn.CommandText=sql
objconn.Execute
set objconn=Nothing
response.redirect "register_job_seeker_stage2.asp"
end if
|