Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > MySQL
|
MySQL General discussion about the MySQL database.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the MySQL section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 16th, 2003, 02:31 PM
Registered User
 
Join Date: Oct 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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







Similar Threads
Thread Thread Starter Forum Replies Last Post
What is wrong with following Insert Query? [email protected] VB.NET 2002/2003 Basics 1 September 19th, 2006 04:41 PM
Insert into & order by... kiwikencox SQL Server 2000 5 October 13th, 2005 05:06 AM
SELECT/ORDER/INSERT Stuart Stalker SQL Server DTS 1 July 24th, 2005 01:00 AM
What is wrong with this insert statement? method SQL Server 2000 13 April 27th, 2005 11:46 PM
Select Distinct Order by... MichaelTJ SQL Language 2 November 17th, 2003 12:49 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.