<%
conn.Close ' Close Connection
Set conn = Nothing
%>
<%
'-------------------------------------------------------------------------------
' Function LoadData
' - Load Data based on Key Value
' - Variables setup: field variables
Function LoadData()
Dim sSql, rs, sWhere, sGroupBy, sHaving, sOrderBy
sSql = "SELECT * FROM [testimonies]"
sWhere = ""
sGroupBy = ""
sHaving = ""
sOrderBy = ""
If sWhere <> "" Then sWhere = sWhere & " AND "
sWhere = sWhere & "([ID] = " & AdjustSql(x_ID) & ")"
sSql = sSql & " WHERE " & sWhere
If sGroupBy <> "" Then
sSql = sSql & " GROUP BY " & sGroupBy
End If
If sHaving <> "" Then
sSql = sSql & " HAVING " & sHaving
End If
If sOrderBy <> "" Then
sSql = sSql & " ORDER BY " & sOrderBy
End If
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open sSql, conn
If rs.Eof Then
LoadData = False
Else
LoadData = True
rs.MoveFirst
' Get the field contents
x_ID = rs("ID")
x_Names = rs("Names")
x_address = rs("address")
x_Country = rs("Country")
x_Phone = rs("Phone")
x_Sex = rs("Sex")
x_Email = rs("Email")
x_purpose = rs("purpose")
x_message = rs("message")
End If
rs.Close
Set rs = Nothing
End Function
%>
<%
'-------------------------------------------------------------------------------
' Function AddData
' - Add Data
' - Variables used: field variables
Function AddData()
Dim sSql, rs, sWhere, sGroupBy, sHaving, sOrderBy
Dim bCheckKey, sSqlChk, sWhereChk
sSql = "SELECT * FROM [testimonies]"
sWhere = ""
sGroupBy = ""
sHaving = ""
sOrderBy = ""
' Check for duplicate key
bCheckKey = True
sWhereChk = sWhere
If x_ID = "" Or IsNull(x_ID) Then
bCheckKey = False
Else
If sWhereChk <> "" Then sWhereChk = sWhereChk & " AND "
sWhereChk = sWhereChk & "([ID] = " & AdjustSql(x_ID) & ")"
End If
If bCheckKey Then
sSqlChk = sSql & " WHERE " & sWhereChk
Set rsChk = conn.Execute(sSqlChk)
If Not rsChk.Eof Then
Session("ewmsg") = "Duplicate value for primary key"
rsChk.Close
Set rsChk = Nothing
AddData = False
Exit Function
End If
rsChk.Close
Set rsChk = Nothing
End If
' Add New Record
If sWhere <> "" Then sWhere = sWhere & " AND "
sWhere = sWhere & "(0 = 1)"
sSql = sSql & " WHERE " & sWhere
If sGroupBy <> "" Then
sSql = sSql & " GROUP BY " & sGroupBy
End If
If sHaving <> "" Then
sSql = sSql & " HAVING " & sHaving
End If
If sOrderBy <> "" Then
sSql = sSql & " ORDER BY " & sOrderBy
End If
Set rs = Server.CreateObject("ADODB.Recordset")
rs.CursorLocation = 3
rs.Open sSql, conn, 1, 2
rs.AddNew
' Field Names
sTmp = Trim(x_Names)
If Trim(sTmp) = "" Then sTmp = Null
rs("Names") = sTmp
' Field address
sTmp = Trim(x_address)
If Trim(sTmp) = "" Then sTmp = Null
rs("address") = sTmp
' Field Country
sTmp = Trim(x_Country)
If Trim(sTmp) = "" Then sTmp = Null
rs("Country") = sTmp
' Field Phone
sTmp = Trim(x_Phone)
If Trim(sTmp) = "" Then sTmp = Null
rs("Phone") = sTmp
' Field Sex
sTmp = Trim(x_Sex)
If Trim(sTmp) = "" Then sTmp = Null
rs("Sex") = sTmp
' Field Email
sTmp = Trim(x_Email)
If Trim(sTmp) = "" Then sTmp = Null
rs("Email") = sTmp
' Field purpose
sTmp = Trim(x_purpose)
If Trim(sTmp) = "" Then sTmp = Null
rs("purpose") = sTmp
' Field message
sTmp = Trim(x_message)
If Trim(sTmp) = "" Then sTmp = Null
rs("message") = sTmp
rs.Update
rs.Close
Set rs = Nothing
AddData = True
End Function
%>