Felipo 0 Newbie Poster

Below is a snippet of the actual code that dreamweaver generates to authenticate "username" is unique prior to it being added to the database - The code works fine - My problem is that I want to also make sure that the email field is also unique (email is the primary key to the database table I am using) I would like to catch the duplicate email field for that record prior to it being added to the database thus creating a REAL DUP KEY comdition for the database - Is there an easy way to incorproate the check for email along with the check for username - Should I duplicate this code and and replace the username with email - Not sure what to do - Would appreciate the help - Thanks -

<%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/ConnRegistration.asp" -->
<%
// *** Edit Operations: declare variables

// set the form action variable
var MM_editAction = Request.ServerVariables("SCRIPT_NAME");
if (Request.QueryString) {
  MM_editAction += "?" + Server.HTMLEncode(Request.QueryString);
}

// boolean to abort record edit
var MM_abortEdit = false;

// query string to execute
var MM_editQuery = "";
%>
<%
// *** Redirect if username exists
var MM_flag="MM_insert";
if (String(Request(MM_flag)) != "undefined") {
  var MM_dupKeyRedirect="GuestRegistrationError.asp";
  var MM_rsKeyConnection=MM_ConnRegistration_STRING;
  var MM_dupKeyUsernameValue = String(Request.Form("Username"));
  var MM_dupKeySQL = "SELECT RegUserName FROM Registration WHERE RegUserName='" + MM_dupKeyUsernameValue.replace(/'/g, "''") + "'"
  var MM_adodbRecordset = "ADODB.Recordset";
  var MM_rsKey = Server.CreateObject(MM_adodbRecordset);
  MM_rsKey.ActiveConnection = MM_rsKeyConnection;
  MM_rsKey.Source = MM_dupKeySQL;
  MM_rsKey.CursorType=0;
  MM_rsKey.CursorLocation=2;
  MM_rsKey.LockType=3;
  MM_rsKey.Open();
  if (!MM_rsKey.EOF || !MM_rsKey.BOF) {
    // the username was found - can not add the requested username
    var MM_qsChar = "?";
    if (MM_dupKeyRedirect.indexOf("?") >= 0) MM_qsChar = "&";
    MM_dupKeyRedirect = MM_dupKeyRedirect + MM_qsChar + "requsername=" + MM_dupKeyUsernameValue;
    Response.Redirect(MM_dupKeyRedirect);
  }
  MM_rsKey.Close();
}
%>
<%
// *** Insert Record: set variables

if (String(Request("MM_insert")) == "GuestRegistrationForm") {

  var MM_editConnection = MM_ConnRegistration_STRING;
  var MM_editTable  = "Registration";
  var MM_editRedirectUrl = "GuestRegistrationConfirmation.asp";
  var MM_fieldsStr = "FirstName|value|LastName|value|City|value|State|value|Email|value|Username|value|Password|value|Status|value";
  var MM_columnsStr = "RegFirstName|',none,''|RegLastName|',none,''|RegCity|',none,''|RegState|',none,''|RegEmail|',none,''|RegUserName|',none,''|RegPassword|',none,''|RegStatus|',none,''";

  // create the MM_fields and MM_columns arrays
  var MM_fields = MM_fieldsStr.split("|");
  var MM_columns = MM_columnsStr.split("|");

  // set the form values
  for (var i=0; i+1 < MM_fields.length; i+=2) {
    MM_fields[i+1] = String(Request.Form(MM_fields[i]));
  }

  // append the query string to the redirect URL
  if (MM_editRedirectUrl && Request.QueryString && Request.QueryString.Count > 0) {
    MM_editRedirectUrl += ((MM_editRedirectUrl.indexOf('?') == -1)?"?":"&") + Request.QueryString;
  }
}
%>
<%
// *** Insert Record: construct a sql insert statement and execute it

if (String(Request("MM_insert")) != "undefined") {

  // create the sql insert statement
  var MM_tableValues = "", MM_dbValues = "";
  for (var i=0; i+1 < MM_fields.length; i+=2) {
    var formVal = MM_fields[i+1];
    var MM_typesArray = MM_columns[i+1].split(",");
    var delim =    (MM_typesArray[0] != "none") ? MM_typesArray[0] : "";
    var altVal =   (MM_typesArray[1] != "none") ? MM_typesArray[1] : "";
    var emptyVal = (MM_typesArray[2] != "none") ? MM_typesArray[2] : "";
    if (formVal == "" || formVal == "undefined") {
      formVal = emptyVal;
    } else {
      if (altVal != "") {
        formVal = altVal;
      } else if (delim == "'") { // escape quotes
        formVal = "'" + formVal.replace(/'/g,"''") + "'";
      } else {
        formVal = delim + formVal + delim;
      }
    }
    MM_tableValues += ((i != 0) ? "," : "") + MM_columns[i];
    MM_dbValues += ((i != 0) ? "," : "") + formVal;
  }
  MM_editQuery = "insert into " + MM_editTable + " (" + MM_tableValues + ") values (" + MM_dbValues + ")";

  if (!MM_abortEdit) {
    // execute the insert
    var MM_editCmd = Server.CreateObject('ADODB.Command');
    MM_editCmd.ActiveConnection = MM_editConnection;
    MM_editCmd.CommandText = MM_editQuery;
    MM_editCmd.Execute();
    MM_editCmd.ActiveConnection.Close();

    if (MM_editRedirectUrl) {
      Response.Redirect(MM_editRedirectUrl);
    }
  }

}
%>
<%
var rsGuestRegistration = Server.CreateObject("ADODB.Recordset");
rsGuestRegistration.ActiveConnection = MM_ConnRegistration_STRING;
rsGuestRegistration.Source = "SELECT RegFirstName, RegLastName, RegCity, RegState, RegEmail, RegUserName, RegPassword, RegStatus FROM Registration";
rsGuestRegistration.CursorType = 0;
rsGuestRegistration.CursorLocation = 2;
rsGuestRegistration.LockType = 1;
rsGuestRegistration.Open();
var rsGuestRegistration_numRows = 0;
%>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.