Hi guys, i'm trying to write an if then statement that checks to see if a name is already in my sql database. If it is i want to go back to my form and say tha name is in there. i've written the code but it's still inserting duplicate names in the database. Here's the code, any help would be greatly appreciated.
<%@ LANGUAGE="VBSCRIPT" %>
<%
Option Explicit
Response.Buffer = True
Response.ContentType = "text/html; charset=iso-8859-1"
'------------------------------------------------------------------------------
'--- Module: SubmitCust.asp
'---
'--- Version: 1.0
'---
'--- Purpose: This will take the values inputted on the Customers form,
'--- and insert them into the correct database tables.
'---
'--- Dependencies:
'---
'--- Notes:
'---
'--- Author: Gene Magerr genemagerr@hotmail.com
'--- Copyright 2001 Magerr Media all rights reserved
'------------------------------------------------------------------------------
%><!--#include file="../../adovbs.inc"--><%
'------------------------------------------------------------------------------
Dim cnCust, rsCust
'------------------------------------------------------------------------------
'--- Declarations
'------------------------------------------------------------------------------
Set cnCust = Server.CreateObject("ADODB.Connection"
cnCust.Open "DSN=Fastlink;uid=sa;pwd=;database=Fastlink"
Set rsCust = Server.CreateObject("ADODB.Recordset"
rsCust.Open "Customers", cnCust, adOpenStatic, adLockOptimistic
If rsCust("CustCompanyName"
<> Request.Form("CustCompanyName"
Then
rsCust.addnew
rsCust("CustCompanyName"
= Request.Form("CustCompanyName"
rsCust("CustContactName"
= Request.Form("CustContactName"
rsCust("CustContactTitle"
= Request.Form("CustContactTitle"
rsCust("CustAddress"
= Request.Form("CustAddress"
rsCust("CustCity"
= Request.Form("CustCity"
rsCust("CustState"
= Request.Form("CustState"
rsCust("CustZip"
= Request.Form("CustZip"
rsCust("CustEmail"
= Request.Form("CustEmail"
rsCust("CustPhone"
= Request.Form("CustPhone"
rsCust.Update
rsCust.MoveLast
Else
Response.Redirect "AddCust.asp?CustExists"
End If
Response.Redirect "CustAddSuccess.asp"
'------------------------------------------------------------------------------
'--- Initialization
'------------------------------------------------------------------------------
'------------------------------------------------------------------------------
'--- Body
'------------------------------------------------------------------------------
'------------------------------------------------------------------------------
'--- Begin HTML output
'------------------------------------------------------------------------------
%>
<HTML>
<HEAD>
<TITLE>Untitled</TITLE>
</HEAD>
<BODY>
</BODY>
</HTML>
<%
'------------------------------------------------------------------------------
'--- End HTML Output
'------------------------------------------------------------------------------
rsCust.Close
Set rsCust = Nothing
cnCust.Close
Set cnCust = Nothing
'------------------------------------------------------------------------------
'--- All ASP post processing code goes here, as well as
'--- sub routines and functions
'------------------------------------------------------------------------------
%>
<%@ LANGUAGE="VBSCRIPT" %>
<%
Option Explicit
Response.Buffer = True
Response.ContentType = "text/html; charset=iso-8859-1"
'------------------------------------------------------------------------------
'--- Module: SubmitCust.asp
'---
'--- Version: 1.0
'---
'--- Purpose: This will take the values inputted on the Customers form,
'--- and insert them into the correct database tables.
'---
'--- Dependencies:
'---
'--- Notes:
'---
'--- Author: Gene Magerr genemagerr@hotmail.com
'--- Copyright 2001 Magerr Media all rights reserved
'------------------------------------------------------------------------------
%><!--#include file="../../adovbs.inc"--><%
'------------------------------------------------------------------------------
Dim cnCust, rsCust
'------------------------------------------------------------------------------
'--- Declarations
'------------------------------------------------------------------------------
Set cnCust = Server.CreateObject("ADODB.Connection"
cnCust.Open "DSN=Fastlink;uid=sa;pwd=;database=Fastlink"
Set rsCust = Server.CreateObject("ADODB.Recordset"
rsCust.Open "Customers", cnCust, adOpenStatic, adLockOptimistic
If rsCust("CustCompanyName"
rsCust.addnew
rsCust("CustCompanyName"
rsCust("CustContactName"
rsCust("CustContactTitle"
rsCust("CustAddress"
rsCust("CustCity"
rsCust("CustState"
rsCust("CustZip"
rsCust("CustEmail"
rsCust("CustPhone"
rsCust.Update
rsCust.MoveLast
Else
Response.Redirect "AddCust.asp?CustExists"
End If
Response.Redirect "CustAddSuccess.asp"
'------------------------------------------------------------------------------
'--- Initialization
'------------------------------------------------------------------------------
'------------------------------------------------------------------------------
'--- Body
'------------------------------------------------------------------------------
'------------------------------------------------------------------------------
'--- Begin HTML output
'------------------------------------------------------------------------------
%>
<HTML>
<HEAD>
<TITLE>Untitled</TITLE>
</HEAD>
<BODY>
</BODY>
</HTML>
<%
'------------------------------------------------------------------------------
'--- End HTML Output
'------------------------------------------------------------------------------
rsCust.Close
Set rsCust = Nothing
cnCust.Close
Set cnCust = Nothing
'------------------------------------------------------------------------------
'--- All ASP post processing code goes here, as well as
'--- sub routines and functions
'------------------------------------------------------------------------------
%>