F
Faith
Okay I am trying to get the id of the row that this form
inputs into the table. The ID auto increments. Is this
possible? Help or even code snippets would help me!
<%@ Language = "VBScript" %>
<!-- #include file="data/adovbs.inc" -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
Transitional//EN" "http://www.w3.org/TR/REC-
html40/loose.dtd">
<html>
<head>
<%
dim strHeaderText
dim strHeaderText2
strHeaderText = "Help Desk"
strHeaderText2 = "Enter a Help Desk Ticket"
dim strCurrentPage, lPos, lLastSlash, iPosition
'** This removes everything in front of the last /
character
strCurrentPage = Request.ServerVariables("SCRIPT_NAME")
lPos = 1
while lPos < len(strCurrentPage)
if mid(strCurrentPage,lPos,1) = "/" then
lLastSlash = lPos + 1
end if
lPos = lPos + 1
wend
strCurrentPage = mid(strCurrentPage,lLastSlash)
%>
<!--#include file="Nav-Header.asp" -->
<!---------------------------------------------------------
-----------------------------------------------------------
----------------------------->
<%
' *** Begin DB Setup ***
Dim strConnString
' Override with our site-wide CONN string.
strConnString = "Provider=SQLOLEDB;Data Source=WWW2;" _
& "Initial Catalog=XXXX;User
Id=XXXX;Password=XXXX;" _
& "Connect Timeout=15;Network Library=dbmssocn;"
Dim cnnFormToDB ' CONN object
Dim strSQL ' String in which to build our SQL
command
Dim lngRecsAffected ' # of records affected... just
informational
' Vars for the fields read in from the form.
Dim strID
Dim strLongDescription
Dim strEntryDate
Dim strUserPriority
Dim strNumber
Dim strEmail
Dim strUserName
Dim strErrorMsg ' Holds error message if we catch
any problems.
'Email Variables
Dim objCDO ' Our CDO object
Dim strTo ' Strings to hold our email fields
Dim strBcc
Dim strFrom
Dim strSubject
Dim strBody
' See if we have any info to process.
If Request.Form("action") <> "Save Form Data" and strTo
= "" Then
' Show the form
%>
<p class="body">
Please enter a description of your problem, the
priority level you feel it merits, and a contact number.
That's it!<BR>Someone from the Help
Desk will call you back as soon as they are available.
</p>
<form action="<%= Request.ServerVariables
("SCRIPT_NAME") %>" method="post" name="ticket">
<input type="hidden" name="action" value="Save
Form Data">
<input type="hidden" maxlength="9"
name="entry_date" size="9" value="<%= FormatDateTime(NOW) %
name="user_name" size="35" value="<%Response.Write(Session
("user_name"))%>">
<table>
<tr>
<td align="right"><strong>User
Name:</strong></td>
<td class="body" nowrap><%Response.Write
(Session("user_name"))%></td>
</tr>
<tr>
<td align="right"><strong>Date &
Time:</strong></td>
<td class="body" nowrap><%= FormatDateTime
(NOW) %></td>
</tr>
<tr>
<td align="right"><strong>Problem
Description:</strong></td>
<td class="body" nowrap><textarea
cols="55" maxlength="500" rows="3" name="long_description"
id="long_description"></textarea></td>
</tr>
<tr>
<td align="right"><strong>User
Priority:</strong></td>
<td class="body" nowrap>
<select name="user_priority"
id="user_priority">
<option value="1">High</option>
<option value="2">Medium</option>
<option value="3" SELECTED>Low</option>
</select> <A class="nav"
HREF="javascript:" onClick="window.open
('priority.asp','','height=500,width=500,location=no,menuba
r=no,resizable=no,scrollbars=yes,status=no,toolbar=no,direc
tories=no')" >CHOOSING A PRIORITY FOR YOUR CASE</A>
</td>
</tr>
<tr>
<td align="right"><strong>Contact Phone
Number:</strong></td>
<td class="body" nowrap><input type="text"
maxlength="12" name="number" size="35"></td>
</tr>
<tr>
<td
align="right"><strong>Email:</strong></td>
<td class="body" nowrap><input type="text"
maxlength="150" name="email" size="35"></td>
</tr>
<tr>
<td> </td>
<td>
<input type="reset" value="Clear">
<input type="submit" value="Save">
</td>
</tr>
</table>
</form>
<%
Else
' Do our DB insert!
strLongDescription = Request.Form
("long_description")
strEntryDate = Request.Form("entry_date")
strUserPriority = Request.Form("user_priority")
strUserName = Request.Form("user_name")
strEmail = Request.Form("email")
strNumber = Request.Form("number")
strLongDescription = Replace
(strLongDescription, "'", "''")
strEntryDate = Replace(strEntryDate, "'", "''")
strUserPriority = Replace
(strUserPriority, "'", "''")
strUserName = Replace(strUserName, "'", "''")
strEmail = Replace(strEmail, "'", "''")
strNumber = Replace(strNumber, "'", "''")
' Open connection to the DB
Set cnnFormToDB = Server.CreateObject
("ADODB.Connection")
cnnFormToDB.Open strConnString
' Build our SQL String
strSQL = ""
strSQL = strSQL & "INSERT INTO
problem_reports "
strSQL = strSQL & "(long_description,
entry_date, user_priority, user_name, email, number) " &
vbCrLf
strSQL = strSQL & "VALUES ("
strSQL = strSQL & "'" & strLongDescription
& "'"
strSQL = strSQL & ", "
strSQL = strSQL & "'" & strEntryDate & "'"
strSQL = strSQL & ", "
strSQL = strSQL & "'" & strUserPriority
& "'"
strSQL = strSQL & ", "
strSQL = strSQL & "'" & strUserName & "'"
strSQL = strSQL & ", "
strSQL = strSQL & "'" & strEmail & "'"
strSQL = strSQL & ", "
strSQL = strSQL & "'" & strNumber & "'"
strSQL = strSQL & ");"
'Email Form to the User and Help Desk on what they have
entered
strTo = Request.Form("email")
strFrom = "Help Desk <[email protected]>"
strBcc = "(e-mail address removed)"
strSubject = "New Help Desk Ticket was Created"
strBody = "<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0
Transitional//EN"">" & vbCrLf _
& "<html>" & vbCrLf _
& "<head>" & vbCrLf _
& "<title>Your Help Desk Ticket Was
Posted</title>" & vbCrLf _
& "<meta http-equiv=Content-Type
content=""text/html; charset=iso-8859-1"">" & vbCrLf _
& "</head>" & vbCrLf _
& "<body bgcolor=""#b8d1e0"">" & vbCrLf _
& "<h2>Thanks for submitting your
information!</h2>" & vbCrLf _
& "<p>" & vbCrLf _
& "<B>Entry Date:</B> " & strEntryDate
& "<BR>" & vbCrLf _
& "<B>User:</B> " & strUserName & "<BR>" &
vbCrLf _
& "<B>Contact Number:</B> " & strNumber
& "<BR>" & vbCrLf _
& "<B>Problem Description:</B> " &
strLongDescription & "<BR>" & vbCrLf _
& "</p>" & vbCrLf _
& "<font size=""-1"">" & vbCrLf _
& "<p>Please address all concerns to
(e-mail address removed).</p>" & vbCrLf _
& "<p>This message was sent to: " & strTo
& "</p>" & vbCrLf _
& "<p>This message was sent to: " & strBcc
& "</p>" & vbCrLf _
& "</font>" & vbCrLf _
& "</body>" & vbCrLf _
& "</html>" & vbCrLf
Set objCDO = Server.CreateObject("CDO.Message")
With objCDO
.To = strTo
.From = strFrom
.Bcc = strBcc
.Subject = strSubject
.HtmlBody = strBody
.Send
End With
Set objCDO = Nothing
' Execute the SQL command. I pass it a
variable lngRecsAffected
' in which to return the number of records
affected. I also tell
' it that this is a text command and it
won't be returing any
' records... this helps it execute the
script faster!
' And before you ask... I don't know, but
YES IT IS OR!!!
cnnFormToDB.Execute strSQL,
lngRecsAffected, adCmdText Or adExecuteNoRecords
' Dispose of the CONN object
cnnFormToDB.Close
Set cnnFormToDB = Nothing
' Display a verification message and we're
done!
%>
<!---------------------------------------------------------
-----------------------------------------------------------
------------------------------------->
<P class="body">
<!---------------------------------------------------------
-----------------------------------------------------------
------------------------------------->
<% Response.Write "<h2>Your trouble ticket
# was opened as of " & strEntryDate & "</h2>" & vbCrLf %>
<% Response.Write "<B>User:</B> " &
strUserName & "<BR>" & vbCrLf %>
<% Response.Write "<B>Priority:</B> " &
strUserPriority & "<BR>" & vbCrLf %>
<% Response.Write "<B>Contact
Number:</B> " & strNumber & "<BR>" & vbCrLf %>
</P>
<p>
<strong>Number of records
affected:</strong> <%= lngRecsAffected %>
</p>
<UL>
</UL>
<!---------------------------------------------------------
-----------------------------------------------------------
------------------------------------->
<%
End If
'End If
%>
<!--#include file="Nav-Footer.asp" -->
inputs into the table. The ID auto increments. Is this
possible? Help or even code snippets would help me!
<%@ Language = "VBScript" %>
<!-- #include file="data/adovbs.inc" -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
Transitional//EN" "http://www.w3.org/TR/REC-
html40/loose.dtd">
<html>
<head>
<%
dim strHeaderText
dim strHeaderText2
strHeaderText = "Help Desk"
strHeaderText2 = "Enter a Help Desk Ticket"
dim strCurrentPage, lPos, lLastSlash, iPosition
'** This removes everything in front of the last /
character
strCurrentPage = Request.ServerVariables("SCRIPT_NAME")
lPos = 1
while lPos < len(strCurrentPage)
if mid(strCurrentPage,lPos,1) = "/" then
lLastSlash = lPos + 1
end if
lPos = lPos + 1
wend
strCurrentPage = mid(strCurrentPage,lLastSlash)
%>
<!--#include file="Nav-Header.asp" -->
<!---------------------------------------------------------
-----------------------------------------------------------
----------------------------->
<%
' *** Begin DB Setup ***
Dim strConnString
' Override with our site-wide CONN string.
strConnString = "Provider=SQLOLEDB;Data Source=WWW2;" _
& "Initial Catalog=XXXX;User
Id=XXXX;Password=XXXX;" _
& "Connect Timeout=15;Network Library=dbmssocn;"
Dim cnnFormToDB ' CONN object
Dim strSQL ' String in which to build our SQL
command
Dim lngRecsAffected ' # of records affected... just
informational
' Vars for the fields read in from the form.
Dim strID
Dim strLongDescription
Dim strEntryDate
Dim strUserPriority
Dim strNumber
Dim strEmail
Dim strUserName
Dim strErrorMsg ' Holds error message if we catch
any problems.
'Email Variables
Dim objCDO ' Our CDO object
Dim strTo ' Strings to hold our email fields
Dim strBcc
Dim strFrom
Dim strSubject
Dim strBody
' See if we have any info to process.
If Request.Form("action") <> "Save Form Data" and strTo
= "" Then
' Show the form
%>
<p class="body">
Please enter a description of your problem, the
priority level you feel it merits, and a contact number.
That's it!<BR>Someone from the Help
Desk will call you back as soon as they are available.
</p>
<form action="<%= Request.ServerVariables
("SCRIPT_NAME") %>" method="post" name="ticket">
<input type="hidden" name="action" value="Save
Form Data">
<input type="hidden" maxlength="9"
name="entry_date" size="9" value="<%= FormatDateTime(NOW) %
<input type="hidden" maxlength="100"
name="user_name" size="35" value="<%Response.Write(Session
("user_name"))%>">
<table>
<tr>
<td align="right"><strong>User
Name:</strong></td>
<td class="body" nowrap><%Response.Write
(Session("user_name"))%></td>
</tr>
<tr>
<td align="right"><strong>Date &
Time:</strong></td>
<td class="body" nowrap><%= FormatDateTime
(NOW) %></td>
</tr>
<tr>
<td align="right"><strong>Problem
Description:</strong></td>
<td class="body" nowrap><textarea
cols="55" maxlength="500" rows="3" name="long_description"
id="long_description"></textarea></td>
</tr>
<tr>
<td align="right"><strong>User
Priority:</strong></td>
<td class="body" nowrap>
<select name="user_priority"
id="user_priority">
<option value="1">High</option>
<option value="2">Medium</option>
<option value="3" SELECTED>Low</option>
</select> <A class="nav"
HREF="javascript:" onClick="window.open
('priority.asp','','height=500,width=500,location=no,menuba
r=no,resizable=no,scrollbars=yes,status=no,toolbar=no,direc
tories=no')" >CHOOSING A PRIORITY FOR YOUR CASE</A>
</td>
</tr>
<tr>
<td align="right"><strong>Contact Phone
Number:</strong></td>
<td class="body" nowrap><input type="text"
maxlength="12" name="number" size="35"></td>
</tr>
<tr>
<td
align="right"><strong>Email:</strong></td>
<td class="body" nowrap><input type="text"
maxlength="150" name="email" size="35"></td>
</tr>
<tr>
<td> </td>
<td>
<input type="reset" value="Clear">
<input type="submit" value="Save">
</td>
</tr>
</table>
</form>
<%
Else
' Do our DB insert!
strLongDescription = Request.Form
("long_description")
strEntryDate = Request.Form("entry_date")
strUserPriority = Request.Form("user_priority")
strUserName = Request.Form("user_name")
strEmail = Request.Form("email")
strNumber = Request.Form("number")
strLongDescription = Replace
(strLongDescription, "'", "''")
strEntryDate = Replace(strEntryDate, "'", "''")
strUserPriority = Replace
(strUserPriority, "'", "''")
strUserName = Replace(strUserName, "'", "''")
strEmail = Replace(strEmail, "'", "''")
strNumber = Replace(strNumber, "'", "''")
' Open connection to the DB
Set cnnFormToDB = Server.CreateObject
("ADODB.Connection")
cnnFormToDB.Open strConnString
' Build our SQL String
strSQL = ""
strSQL = strSQL & "INSERT INTO
problem_reports "
strSQL = strSQL & "(long_description,
entry_date, user_priority, user_name, email, number) " &
vbCrLf
strSQL = strSQL & "VALUES ("
strSQL = strSQL & "'" & strLongDescription
& "'"
strSQL = strSQL & ", "
strSQL = strSQL & "'" & strEntryDate & "'"
strSQL = strSQL & ", "
strSQL = strSQL & "'" & strUserPriority
& "'"
strSQL = strSQL & ", "
strSQL = strSQL & "'" & strUserName & "'"
strSQL = strSQL & ", "
strSQL = strSQL & "'" & strEmail & "'"
strSQL = strSQL & ", "
strSQL = strSQL & "'" & strNumber & "'"
strSQL = strSQL & ");"
'Email Form to the User and Help Desk on what they have
entered
strTo = Request.Form("email")
strFrom = "Help Desk <[email protected]>"
strBcc = "(e-mail address removed)"
strSubject = "New Help Desk Ticket was Created"
strBody = "<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0
Transitional//EN"">" & vbCrLf _
& "<html>" & vbCrLf _
& "<head>" & vbCrLf _
& "<title>Your Help Desk Ticket Was
Posted</title>" & vbCrLf _
& "<meta http-equiv=Content-Type
content=""text/html; charset=iso-8859-1"">" & vbCrLf _
& "</head>" & vbCrLf _
& "<body bgcolor=""#b8d1e0"">" & vbCrLf _
& "<h2>Thanks for submitting your
information!</h2>" & vbCrLf _
& "<p>" & vbCrLf _
& "<B>Entry Date:</B> " & strEntryDate
& "<BR>" & vbCrLf _
& "<B>User:</B> " & strUserName & "<BR>" &
vbCrLf _
& "<B>Contact Number:</B> " & strNumber
& "<BR>" & vbCrLf _
& "<B>Problem Description:</B> " &
strLongDescription & "<BR>" & vbCrLf _
& "</p>" & vbCrLf _
& "<font size=""-1"">" & vbCrLf _
& "<p>Please address all concerns to
(e-mail address removed).</p>" & vbCrLf _
& "<p>This message was sent to: " & strTo
& "</p>" & vbCrLf _
& "<p>This message was sent to: " & strBcc
& "</p>" & vbCrLf _
& "</font>" & vbCrLf _
& "</body>" & vbCrLf _
& "</html>" & vbCrLf
Set objCDO = Server.CreateObject("CDO.Message")
With objCDO
.To = strTo
.From = strFrom
.Bcc = strBcc
.Subject = strSubject
.HtmlBody = strBody
.Send
End With
Set objCDO = Nothing
' Execute the SQL command. I pass it a
variable lngRecsAffected
' in which to return the number of records
affected. I also tell
' it that this is a text command and it
won't be returing any
' records... this helps it execute the
script faster!
' And before you ask... I don't know, but
YES IT IS OR!!!
cnnFormToDB.Execute strSQL,
lngRecsAffected, adCmdText Or adExecuteNoRecords
' Dispose of the CONN object
cnnFormToDB.Close
Set cnnFormToDB = Nothing
' Display a verification message and we're
done!
%>
<!---------------------------------------------------------
-----------------------------------------------------------
------------------------------------->
<P class="body">
<!---------------------------------------------------------
-----------------------------------------------------------
------------------------------------->
<% Response.Write "<h2>Your trouble ticket
# was opened as of " & strEntryDate & "</h2>" & vbCrLf %>
<% Response.Write "<B>User:</B> " &
strUserName & "<BR>" & vbCrLf %>
<% Response.Write "<B>Priority:</B> " &
strUserPriority & "<BR>" & vbCrLf %>
<% Response.Write "<B>Contact
Number:</B> " & strNumber & "<BR>" & vbCrLf %>
</P>
<p>
<strong>Number of records
affected:</strong> <%= lngRecsAffected %>
</p>
<UL>
</UL>
<!---------------------------------------------------------
-----------------------------------------------------------
------------------------------------->
<%
End If
'End If
%>
<!--#include file="Nav-Footer.asp" -->