4 Replies Latest reply on Jul 13, 2006 7:56 PM by RyanG24

    submit form if

    RyanG24 Level 1
      Hi i have a username input form, which contains fields "firstname" "surname" "emailaddress"

      i have a table called users with the same fields, my input works fine but i need to do a check on the table first to see if the name already exsits this is what i want

      if Form.Surname = Users.Surname and Form.FirstName = Users.FirstName and User.EmailAddress = Null
      then enter Form.EmailAddress where they match

      if Form.Surname = Users.Surname and Form.FirstName = Users.FirstName and User.EmailAddress = is Not Null
      then send alert box saying "already a user"

      if none of the above enter new record

      Could someone please start me off on the code
        • 1. Re: submit form if
          Level 7
          Something like:
          <cfif NOT IsDefined ('email')>
          <cfset email = "">
          <cfelse>
          <cfset email= #URL.email#>
          </cfif>
          <cfif IsDefined('Submit')>
          <cfquery name="email_search" datasource="#Request.MainDSN#">
          SELECT email FROM database WHERE email='#FORM.email#'
          </cfquery>
          <cfif email_search.RecordCount GTE 1>
          <cflocation url="index.cfm?reqemail=#FORM.email#&email=taken"
          addtoken="no">
          </cfif>
          <cfif>

          Then in your body have:
          <cfif email NEQ "">Sorry, that email address already exists, please try
          again!</cfif>

          Thats how I did it with my newsletter signup to negate duplicates


          • 2. Re: submit form if
            Dan Bracuk Level 5
            insert into your_table
            (surname, firstname, emailaddress)
            select distinct '#form.surname#', '#form.firstname#', '#form.emailaddress#'
            from some_small_table
            where not exists
            (select surname
            from yourtable
            where surname = '#form.surname#'
            and firstname = '#form.firstname#' )

            By the way, how are you going to cope with two people having the same name?
            • 3. Re: submit form if
              Level 7
              Does it matter if they have the same name and not the same email address?
              Names are not unique in the world.

              Why would this be a requirement?


              • 4. Re: submit form if
                RyanG24 Level 1
                Many thanks good point

                ok there will always be a email address now so what would the code be for

                if Form.Surname = Users.Surname and Form.FirstName = Users.FirstName and Form.EmailAddress = User.EmailAddress
                then send alert box saying "already a user"

                if none of the above enter new record