zou iemand mij kunnen vertellen hoe ik in onderstaand script aan kan passen zodat in de db gekeken wordt of het ingevulde e-mailadres al bestaat of niet?
Op dit moment is het namelijk mogelijk om hetzelfde e-mailadres meerdere keren toe te voegen..
<%
dim lID ' as long
dim sAction ' as string
dim sEmailAddress ' as string
dim sName ' as string
dim lGroups ' as array of long
dim i ' as integer
lID = clng(request("ID"))
sAction = lcase(request("action"))
if lID <> 0 then LoadEmail (lID)
select case sAction
case "save"
sEmailAddress = trim(request("EmailAddress"))
sName = trim(request("achternaam"))
if request("Group").Count > 0 then redim lGroups(request("Group").Count - 1)
for i = 1 to request("Group").Count
lGroups(i-1) = clng(request("Group")(i))
next
SaveEmail lID, sEmailAddress, sName, lGroups
response.redirect "../members.asp"
case "delete"
DeleteEmail lID
response.redirect "../members.asp"
end select
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>E-mail adres</title>
<script language="javascript" src="../../../include/new_validate.js"></script>
<script language="javascript">
function Save()
{
if (isValid(formulier)){
formulier.action.value = "save";
formulier.submit();
}
}
function Delete()
{
formulier.action.value = "delete";
formulier.submit();
}
</script>
<link href="../../acm.css" rel="stylesheet" type="text/css">
</head>
<body>
<form name="formulier" id="formulier" action="email.asp" method="post" target="_self">
<input type="hidden" name="action" value="">
<input type="hidden" name="id" value="<%= lID %>">
<table width="575" border="0" cellpadding="2" cellspacing="0" class="tekst_backoffice">
<tr>
<td width="1%" bgcolor="#d4d0c8"><a href="#" onClick="javascript:Save();">[img]"../../images/kn_save.gif"[/img]</a></td>
<td width="96%" align="right" bgcolor="#d4d0c8"></td>
<td width="1%" bgcolor="#d4d0c8">[img]"../../images/transparant.gif"[/img]</td>
<td width="1%" align="right">[img]"../../images/transparant.gif"[/img]</td>
</tr>
</table>
<br>
<table width="278" border=0 cellpadding=0 cellspacing=0 class="tekst_backoffice">
<tr align=left valign=middle>
<td class="tekst_backoffice" title="E-mail adres"> E-mail adres:<span class="alert">*</span>
</td>
<td>
<input type="text" validator="email" name="EmailAddress" required description="E-mail adres" maxlength="255" size="25" value="<%= sEmailAddress %>">
</td>
</tr>
<tr align=left valign=middle>
<td class="tekst_backoffice" title="Naam"> Naam: </td>
<td>
<input type="text" name="achternaam" description="Achternaam" maxlength="255" size="25" value="<%= sName %>">
</td>
</tr>
<%= BuildGroupList (lID) %>
</table>
<div>
<div align="left"><span class="tekstalert"><br>
<font color="#FF0000">* is een verplicht veld</font></span><font color="#FF0000"><br>
</font><br>
</div>
</div>
<div class="hr"></div>
</form>
</body>
</html>
<%
public sub SaveEmail (lID, sEmailAddress, sName, lGroups)
dim sSQL ' as string
dim i ' as integer
dim rs ' as ADODB.Recordset
'@commment Save updated or new e-mailaddress.
if lID = 0 then
'@comment Insert if group does noet exist yet.
set rs = server.createobject("ADODB.Recordset")
rs.Cursorlocation = adUseServer
rs.Open "tbMember", CONNECTIONSTRING_MAILING, adOpenKeySet, adLockOptimistic, adCmdTableDirect
rs.AddNew
rs.Fields("MemberEmail") = sEmailAddress
rs.Fields("MemberName") = sName
rs.Update
lID = rs.Fields("MemberID").Value
rs.Close
set rs = nothing
else
'@comment Update if group already exists
sSQL = "UPDATE [tbMember] SET MemberEmail = '" & EscapeForSQL(sEmailAddress) & "'," & _
" MemberName = '" & EscapeForSQL(sName) & "'" & _
" WHERE MemberID = " & lID
ExecuteSQL CONNECTIONSTRING_MAILING, sSQL
end if
'@comment Delete previous groups
sSQL = "DELETE FROM AddressGroup WHERE fkMember = " & lID
ExecuteSQL CONNECTIONSTRING_MAILING, sSQL
'@Comment Save updated or new groups
if request("Group").Count > 0 then
for i = lbound(lGroups) to uBound(lGroups)
sSQL = "INSERT INTO AddressGroup (fkMember, fkGroup) VALUES (" & _
lID & ", " & lGroups(i) & ")"
ExecuteSQL CONNECTIONSTRING_MAILING, sSQL
next
end if
end sub
'* Load the data of an e-mail address
'@param lID - the id of the e-mail address
public sub LoadEmail (lID)
dim sSQL ' as string
dim rs ' as ADODB.Recordset
sSQL = "SELECT * FROM tbMember WHERE MemberID = " & lID
set rs = DisconnectedRecordset (CONNECTIONSTRING_MAILING, sSQL)
sEmailAddress = trim(rs.fields("MemberEmail").Value)
sName = trim(rs.fields("MemberName").Value)
rs.close
set rs = nothing
end sub
'* Delete an e-mail address and all its associated data
'@param lID - the ID of the e-mail address you wish to delete.
public sub DeleteEmail(lID)
dim sSQL ' as string
'@comment Delete links to groups.
sSQL = "DELETE FROM AddressGroup WHERE fkMember = " & lID
ExecuteSQL CONNECTIONSTRING_MAILING, sSQL
'@comment Delete member
sSQL = "DELETE FROM tbMember WHERE MemberID = " & lID
ExecuteSQL CONNECTIONSTRING_MAILING, sSQL
end sub
'* Builds a list of all groups with checkbuttons
'@param lAddressID - The ID of the address for which you want to build the grouplist
'@returns a string with the correct HTML for the groupslist.
public function BuildGroupList (lAddressID)
dim sHTML ' as string
dim rsGroup ' as ADODB.Recordset
dim sSQL ' as string
dim lCount ' as long
dim lGroupID ' as integer
dim sChecked ' as string
dim i ' as integer
sSQL = "SELECT ID, Name, Description FROM [Group] ORDER BY Name"
sHTML = ""
set rsGroup = DisconnectedRecordset (CONNECTIONSTRING_MAILING, sSQL)
i = 0
do while not rsGroup.EOF
lGroupID = clng(rsGroup.Fields("ID").Value)
sSQL = "SELECT COUNT (*) FROM AddressGroup WHERE fkMember = " & lAddressID & _
" AND fkGroup = " & lGroupID
lCount = clng(Field(sSQL, CONNECTIONSTRING_MAILING))
if lCount = 0 then
sChecked = ""
else
sChecked = "checked=""checked"""
end if
sHTML = sHTML & "<tr>" & vbcrlf
if i = 0 then
sHTML = sHTML & "<td>Groepen:</td>" & vbcrlf
else
sHTML = sHTML & "<td> </td>" & vbcrlf
end if
i = i + 1
sHTML = sHTML & "<td colspan=""2"">" & vbcrlf
sHTML = SHTML & "<input type=""checkbox"" name=""group"""
sHTML = sHTML & " value=""" & rsGroup.Fields("ID").Value & """"
sHTML = sHTML & " " & sChecked & ">" & vbcrlf
sHTML = sHTML & rsGroup.Fields("Name").Value & " " & rsGroup.Fields("Description").Value
sHTML = sHTML & "</td>" & vbcrlf
sHTML = sHTML & "</tr>" & vbcrlf
rsGroup.Movenext
loop
rsGroup.Close
set rsGroup = nothing
BuildGroupList = sHTML
end function
%>
Op dit moment is het namelijk mogelijk om hetzelfde e-mailadres meerdere keren toe te voegen..
<%
dim lID ' as long
dim sAction ' as string
dim sEmailAddress ' as string
dim sName ' as string
dim lGroups ' as array of long
dim i ' as integer
lID = clng(request("ID"))
sAction = lcase(request("action"))
if lID <> 0 then LoadEmail (lID)
select case sAction
case "save"
sEmailAddress = trim(request("EmailAddress"))
sName = trim(request("achternaam"))
if request("Group").Count > 0 then redim lGroups(request("Group").Count - 1)
for i = 1 to request("Group").Count
lGroups(i-1) = clng(request("Group")(i))
next
SaveEmail lID, sEmailAddress, sName, lGroups
response.redirect "../members.asp"
case "delete"
DeleteEmail lID
response.redirect "../members.asp"
end select
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>E-mail adres</title>
<script language="javascript" src="../../../include/new_validate.js"></script>
<script language="javascript">
function Save()
{
if (isValid(formulier)){
formulier.action.value = "save";
formulier.submit();
}
}
function Delete()
{
formulier.action.value = "delete";
formulier.submit();
}
</script>
<link href="../../acm.css" rel="stylesheet" type="text/css">
</head>
<body>
<form name="formulier" id="formulier" action="email.asp" method="post" target="_self">
<input type="hidden" name="action" value="">
<input type="hidden" name="id" value="<%= lID %>">
<table width="575" border="0" cellpadding="2" cellspacing="0" class="tekst_backoffice">
<tr>
<td width="1%" bgcolor="#d4d0c8"><a href="#" onClick="javascript:Save();">[img]"../../images/kn_save.gif"[/img]</a></td>
<td width="96%" align="right" bgcolor="#d4d0c8"></td>
<td width="1%" bgcolor="#d4d0c8">[img]"../../images/transparant.gif"[/img]</td>
<td width="1%" align="right">[img]"../../images/transparant.gif"[/img]</td>
</tr>
</table>
<br>
<table width="278" border=0 cellpadding=0 cellspacing=0 class="tekst_backoffice">
<tr align=left valign=middle>
<td class="tekst_backoffice" title="E-mail adres"> E-mail adres:<span class="alert">*</span>
</td>
<td>
<input type="text" validator="email" name="EmailAddress" required description="E-mail adres" maxlength="255" size="25" value="<%= sEmailAddress %>">
</td>
</tr>
<tr align=left valign=middle>
<td class="tekst_backoffice" title="Naam"> Naam: </td>
<td>
<input type="text" name="achternaam" description="Achternaam" maxlength="255" size="25" value="<%= sName %>">
</td>
</tr>
<%= BuildGroupList (lID) %>
</table>
<div>
<div align="left"><span class="tekstalert"><br>
<font color="#FF0000">* is een verplicht veld</font></span><font color="#FF0000"><br>
</font><br>
</div>
</div>
<div class="hr"></div>
</form>
</body>
</html>
<%
public sub SaveEmail (lID, sEmailAddress, sName, lGroups)
dim sSQL ' as string
dim i ' as integer
dim rs ' as ADODB.Recordset
'@commment Save updated or new e-mailaddress.
if lID = 0 then
'@comment Insert if group does noet exist yet.
set rs = server.createobject("ADODB.Recordset")
rs.Cursorlocation = adUseServer
rs.Open "tbMember", CONNECTIONSTRING_MAILING, adOpenKeySet, adLockOptimistic, adCmdTableDirect
rs.AddNew
rs.Fields("MemberEmail") = sEmailAddress
rs.Fields("MemberName") = sName
rs.Update
lID = rs.Fields("MemberID").Value
rs.Close
set rs = nothing
else
'@comment Update if group already exists
sSQL = "UPDATE [tbMember] SET MemberEmail = '" & EscapeForSQL(sEmailAddress) & "'," & _
" MemberName = '" & EscapeForSQL(sName) & "'" & _
" WHERE MemberID = " & lID
ExecuteSQL CONNECTIONSTRING_MAILING, sSQL
end if
'@comment Delete previous groups
sSQL = "DELETE FROM AddressGroup WHERE fkMember = " & lID
ExecuteSQL CONNECTIONSTRING_MAILING, sSQL
'@Comment Save updated or new groups
if request("Group").Count > 0 then
for i = lbound(lGroups) to uBound(lGroups)
sSQL = "INSERT INTO AddressGroup (fkMember, fkGroup) VALUES (" & _
lID & ", " & lGroups(i) & ")"
ExecuteSQL CONNECTIONSTRING_MAILING, sSQL
next
end if
end sub
'* Load the data of an e-mail address
'@param lID - the id of the e-mail address
public sub LoadEmail (lID)
dim sSQL ' as string
dim rs ' as ADODB.Recordset
sSQL = "SELECT * FROM tbMember WHERE MemberID = " & lID
set rs = DisconnectedRecordset (CONNECTIONSTRING_MAILING, sSQL)
sEmailAddress = trim(rs.fields("MemberEmail").Value)
sName = trim(rs.fields("MemberName").Value)
rs.close
set rs = nothing
end sub
'* Delete an e-mail address and all its associated data
'@param lID - the ID of the e-mail address you wish to delete.
public sub DeleteEmail(lID)
dim sSQL ' as string
'@comment Delete links to groups.
sSQL = "DELETE FROM AddressGroup WHERE fkMember = " & lID
ExecuteSQL CONNECTIONSTRING_MAILING, sSQL
'@comment Delete member
sSQL = "DELETE FROM tbMember WHERE MemberID = " & lID
ExecuteSQL CONNECTIONSTRING_MAILING, sSQL
end sub
'* Builds a list of all groups with checkbuttons
'@param lAddressID - The ID of the address for which you want to build the grouplist
'@returns a string with the correct HTML for the groupslist.
public function BuildGroupList (lAddressID)
dim sHTML ' as string
dim rsGroup ' as ADODB.Recordset
dim sSQL ' as string
dim lCount ' as long
dim lGroupID ' as integer
dim sChecked ' as string
dim i ' as integer
sSQL = "SELECT ID, Name, Description FROM [Group] ORDER BY Name"
sHTML = ""
set rsGroup = DisconnectedRecordset (CONNECTIONSTRING_MAILING, sSQL)
i = 0
do while not rsGroup.EOF
lGroupID = clng(rsGroup.Fields("ID").Value)
sSQL = "SELECT COUNT (*) FROM AddressGroup WHERE fkMember = " & lAddressID & _
" AND fkGroup = " & lGroupID
lCount = clng(Field(sSQL, CONNECTIONSTRING_MAILING))
if lCount = 0 then
sChecked = ""
else
sChecked = "checked=""checked"""
end if
sHTML = sHTML & "<tr>" & vbcrlf
if i = 0 then
sHTML = sHTML & "<td>Groepen:</td>" & vbcrlf
else
sHTML = sHTML & "<td> </td>" & vbcrlf
end if
i = i + 1
sHTML = sHTML & "<td colspan=""2"">" & vbcrlf
sHTML = SHTML & "<input type=""checkbox"" name=""group"""
sHTML = sHTML & " value=""" & rsGroup.Fields("ID").Value & """"
sHTML = sHTML & " " & sChecked & ">" & vbcrlf
sHTML = sHTML & rsGroup.Fields("Name").Value & " " & rsGroup.Fields("Description").Value
sHTML = sHTML & "</td>" & vbcrlf
sHTML = sHTML & "</tr>" & vbcrlf
rsGroup.Movenext
loop
rsGroup.Close
set rsGroup = nothing
BuildGroupList = sHTML
end function
%>