Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I add a timestamp? 3

Status
Not open for further replies.

ngkatsaras

IS-IT--Management
Jul 28, 2004
72
US
I inherited this "contact us" form code which was apparently created in Dreamweaver originally. It's attached to simple feedback form which updates an MDB file. It works fine, but I'd like to add a timestamp so I can see when each record of feedback was submitted. I've already added a "DATE" column to the MDB file, but I can't figure out how to update this code to add a simple datetimestamp! I'd like to use the "general time" format.

Thanks very much in advance!

Code:
<%
' *** Edit Operations: declare variables

Dim MM_editAction
Dim MM_abortEdit
Dim MM_editQuery
Dim MM_editCmd

Dim MM_editConnection
Dim MM_editTable
Dim MM_editRedirectUrl
Dim MM_editColumn
Dim MM_recordId

Dim MM_fieldsStr
Dim MM_columnsStr
Dim MM_fields
Dim MM_columns
Dim MM_typeArray
Dim MM_formVal
Dim MM_delim
Dim MM_altVal
Dim MM_emptyVal
Dim MM_i

MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
  MM_editAction = MM_editAction & "?" & Request.QueryString
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%>
<%
' *** Insert Record: set variables

If (CStr(Request("MM_insert")) = "form1") Then

  MM_editConnection = MM_DB_STRING
  MM_editTable = "CONTACT"
  MM_editRedirectUrl = "thanks.htm"
  MM_fieldsStr  = "NAME|value|ADRS|value|CITY|value|state|value|ZIP|value|PHONE|value|EMAIL|value|COMMENTS|value"
  MM_columnsStr = "NAME|',none,''|ADRS|',none,''|CITY|',none,''|STATE|',none,''|ZIP|none,none,NULL|PHONE|',none,''|EMAIL|',none,''|COMMENTS|',none,''"

  ' create the MM_fields and MM_columns arrays
  MM_fields = Split(MM_fieldsStr, "|")
  MM_columns = Split(MM_columnsStr, "|")
  
  ' set the form values
  For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
    MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))
  Next

  ' append the query string to the redirect URL
  If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
    If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
      MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
    Else
      MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
    End If
  End If

End If
%>
<%
' *** Insert Record: construct a sql insert statement and execute it

Dim MM_tableValues
Dim MM_dbValues

If (CStr(Request("MM_insert")) <> "") Then

  ' create the sql insert statement
  MM_tableValues = ""
  MM_dbValues = ""
  For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
    MM_formVal = MM_fields(MM_i+1)
    MM_typeArray = Split(MM_columns(MM_i+1),",")
    MM_delim = MM_typeArray(0)
    If (MM_delim = "none") Then MM_delim = ""
    MM_altVal = MM_typeArray(1)
    If (MM_altVal = "none") Then MM_altVal = ""
    MM_emptyVal = MM_typeArray(2)
    If (MM_emptyVal = "none") Then MM_emptyVal = ""
    If (MM_formVal = "") Then
      MM_formVal = MM_emptyVal
    Else
      If (MM_altVal <> "") Then
        MM_formVal = MM_altVal
      ElseIf (MM_delim = "'") Then  ' escape quotes
        MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"
      Else
        MM_formVal = MM_delim + MM_formVal + MM_delim
      End If
    End If
    If (MM_i <> LBound(MM_fields)) Then
      MM_tableValues = MM_tableValues & ","
      MM_dbValues = MM_dbValues & ","
    End If
    MM_tableValues = MM_tableValues & MM_columns(MM_i)
    MM_dbValues = MM_dbValues & MM_formVal
  Next
  MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")"

  If (Not MM_abortEdit) Then
    ' execute the insert
    Set MM_editCmd = Server.CreateObject("ADODB.Command")
    MM_editCmd.ActiveConnection = MM_editConnection
    MM_editCmd.CommandText = MM_editQuery
    'response.Write(MM_editCmd.Execute)
	MM_editCmd.Execute
    MM_editCmd.ActiveConnection.Close

    If (MM_editRedirectUrl <> "") Then
      Response.Redirect(MM_editRedirectUrl)
    End If
  End If

End If
%>

<html>
<head>
<title>::Contact Us::</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="../css/style_main.css" rel="stylesheet" type="text/css">
</head>

<body bgcolor="#000000" leftmargin="0" topmargin="15" marginwidth="0" marginheight="0">
<table width="700" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="[URL unfurl="true"]http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0"[/URL] width="700" height="24">
      <param name="movie" value="history.swf">
      <param name=quality value=high>
      <embed src="history.swf" quality=high pluginspage="[URL unfurl="true"]http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"[/URL] type="application/x-shockwave-flash" width="700" height="24"></embed></object></td>
  </tr>
  <tr>
    <td>      <form ACTION="<%=MM_editAction%>" METHOD="POST" name="form1">
    <table width="700" border="0" cellspacing="0" cellpadding="6">
      <tr>
        <td colspan="3">&nbsp;</td>
      </tr>
      <tr>
        <td><strong><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">Request
            Information Form</font></strong></td>
        <td>&nbsp;</td>
        <td width="263" rowspan="10" valign="top"><div align="left">
              <table width="150" border="0" cellpadding="4" cellspacing="0">
                <tr>
                  <td><font face="Verdana, Arial, Helvetica, sans-serif"><strong><font size="1"><img src="../images/contact_image.jpg" width="200" height="250"></font></strong></font></td>
                </tr>
                <tr>
                  <td><div align="center"><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif"><strong>Corporate
                          Office</strong><br>
                         Miami, FL<br>
                  </td>
                </tr>
                <tr>
                  <td><div align="center"><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif"><strong>Showroom</strong><br>
            New York, NY<br>
</div>
                  </td>
                </tr>
              </table>
              <font face="Verdana, Arial, Helvetica, sans-serif"><strong></strong></font></div>
        </td>
      </tr>
      <tr>
        <td width="175"><div align="right"><font face="Verdana, Arial, Helvetica, sans-serif"><strong><font size="1"><font color="#FFFFFF">Name
                :</font></font></strong></font></div>
        </td>
        <td width="226"><strong><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">
              <input name="NAME" type="text" id="NAME" class="textbox" size="20">
        </font></strong></td>
        </tr>
      <tr>
        <td><div align="right"><font face="Verdana, Arial, Helvetica, sans-serif"><strong><font size="1"><font color="#FFFFFF">Address
                :</font></font></strong></font></div>
        </td>
        <td><strong><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">
              <input name="ADRS" type="text" id="ADRS" class="textbox" size="20">
        </font></strong></td>
        </tr>
      <tr>
        <td><div align="right"><font face="Verdana, Arial, Helvetica, sans-serif"><strong><font size="1"><font color="#FFFFFF">City
                :</font></font></strong></font></div>
        </td>
        <td><strong><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">
              <input name="CITY" type="text" id="CITY" class="textbox" size="20">
        </font></strong></td>
        </tr>
      <tr>
        <td><div align="right"><font face="Verdana, Arial, Helvetica, sans-serif"><strong><font size="1"><font color="#FFFFFF">State
            :</font></font></strong></font></div></td>
        <td><div align="left"><font size="1" face="Verdana, Arial, Helvetica, sans-serif"><select name="state" class="textbox">
			  <option value="AL" selected>AL</option>
              <option value="AR">AR</option>
              <option value="AZ">AZ</option>
              <option value="CA">CA</option>
              <option value="CO">CO</option>
              <option value="CT">CT</option>
              <option value="DE">DE</option>
              <option value="FL">FL</option>
              <option value="GA">GA</option>
              <option value="HI">HI</option>
              <option value="IA">IA</option>
              <option value="ID">ID</option>
              <option value="IL">IL</option>
              <option value="IN">IN</option>
              <option value="KS">KS</option>
              <option value="KY">KY</option>
              <option value="LA">LA</option>
              <option value="MA">MA</option>
              <option value="MD">MD</option>
              <option value="ME">ME</option>
              <option value="MI">MI</option>
              <option value="MN">MN</option>
              <option value="MO">MO</option>
              <option value="MS">MS</option>
              <option value="NC">NC</option>
              <option value="ND">ND</option>
              <option value="NE">NE</option>
              <option value="NH">NH</option>
              <option value="NJ">NJ</option>
              <option value="NM">NM</option>
              <option value="NV">NV</option>
              <option value="NY">NY</option>
              <option value="OH">OH</option>
              <option value="OK">OK</option>
              <option value="OR">OR</option>
              <option value="PA">PA</option>
              <option value="RI">RI</option>
              <option value="SC">SC</option>
              <option value="TN">TN</option>
              <option value="TX">TX</option>
              <option value="VA">VA</option>
              <option value="VI">VI</option>
              <option value="VT">VT</option>
              <option value="WA">WA</option>
              <option value="WI">WI</option>
              </select>
        </font></div></td>
      </tr>
      <tr>
        <td><div align="right"><font face="Verdana, Arial, Helvetica, sans-serif"><strong><font size="1"><font color="#FFFFFF">Zip
                    Code
            :</font></font></strong></font></div></td>
        <td><div align="left"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">
          <input name="ZIP" type="text" class="textbox" id="ZIP" size="20">
        </font></div></td>
      </tr>
      <tr>
        <td><div align="right"><font face="Verdana, Arial, Helvetica, sans-serif"><strong><font size="1"><font color="#FFFFFF">Phone
            :</font></font></strong></font></div></td>
        <td><strong><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">
          <input name="PHONE" type="text" id="PHONE" class="textbox" size="20">
        </font></strong></td>
      </tr>
      <tr>
        <td><div align="right"><font face="Verdana, Arial, Helvetica, sans-serif"><strong><font size="1"><font color="#FFFFFF">E-mail            :</font></font></strong></font></div></td>
        <td><div align="left"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">
          <input name="EMAIL" type="text" class="textbox" id="EMAIL" size="20">
        </font></div></td>
      </tr>
      <tr>
        <td rowspan="2" valign="top"><div align="right"><font face="Verdana, Arial, Helvetica, sans-serif"><strong><font size="1"><font color="#FFFFFF">Comments
                :</font></font></strong></font></div>
        </td>
        <td valign="top"><strong><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">
              <textarea name="COMMENTS" cols="30" rows="6" class="textbox" id="COMMENTS"></textarea>
        </font></strong></td>
        </tr>
      <tr>
        <td valign="top"><strong><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">
          <input name="Submit" type="submit" id="Submit" value="Submit" class="textbox">
          <input type="reset" name="Reset" value="Reset" class="textbox">
        </font></strong></td>
      </tr>
    </table>
      
    
    
    
    
    
    
    
    
    
    
    
    
    <input type="hidden" name="MM_insert" value="form1">
    </form></td>
  </tr>
  <tr>
    <td><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="[URL unfurl="true"]http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0"[/URL] width="700" height="24">
      <param name="movie" value="linea_abajo.swf">
      <param name=quality value=high>
      <embed src="linea_abajo.swf" quality=high pluginspage="[URL unfurl="true"]http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"[/URL] type="application/x-shockwave-flash" width="700" height="24"></embed></object></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>
<font face="Verdana, Arial, Helvetica, sans-serif"><strong></strong></font>
</body>
</html>
 
Code:
MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ",date) values (" & MM_dbValues & ",Now)"


 
Thanks Kendel, that sure looks to me like it should work!
But I'm getting an Internal server error.

These are the columns in my table:

ID NAME ADRS PHONE CITY STATE ZIP EMAIL COMMENTS DATE

Code:
  'MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")"
   MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ",DATE) values (" & MM_dbValues & ",Now)"
 
Is "now" an SQL statement or ASP? I'm trying now to just add a simple insert to add a date as a separate record just to figure this out.

 
I think you should use...

Now()

if you just want the date use Date()

-VJ
 
I tried this and am getting an error still..

Code:
  'MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")"
  MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ",DATE) values (" & MM_dbValues & ",Now())"
 
The page cannot be displayed
There is a problem with the page you are trying to reach and it cannot be displayed.

--------------------------------------------------------------------------------

Please try the following:

Open the home page, and then look for links to the information you want.
Click the Refresh button, or try again later.

Click Search to look for information on the Internet.
You can also see a list of related sites.




HTTP 500 - Internal server error
Internet Explorer
 
Cant tell anything from that error...

go to Control Panel/Internet Option/Advanced tab...

then check the boxes

Show script errors
show friendly Http error messages...

-(not sure of the correct check box details, just writing top off my head...)

after you do this...you can see the actual error in the code...

-VJ
 
Thanks for that tip!

Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement.

/catalog/contact3.asp, line 116
 
For simplification, I tried this.. still getting an error

Code:
  MM_editQuery = "insert into " & MM_editTable & " (DATE) values (Now())"
 
change your query to:

MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ",SubmitDate) values (" & MM_dbValues & ",Now())"

DATE is a key word, so its not suggested to use it in queries...

and i was just making correction to the Kendel's post...and i did not go thru your post...

Are you trying to insert a new field that has the timestamp value on every insert...???

Explain your problem a little bit more clear..

-VJ



 
THANK YOU!!! That fixed it.. darned DATE reserved word!
 
The time is showing 3 hours behind, how can I add 3 hours?!
 
The DateAdd function

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
Need an expensive ASP developer in the North Carolina area? Feel free to let me know.


 
Thanks! After figuring out I had to put quotes around the h, I got it to work.

Code:
  MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ",SUBMITDATE) values (" & MM_dbValues & ",DateAdd('h',3,Now()))"
 
Thanks amorous, I forgot the reserved word. For the Now function, I can use it without () and it still work though.

To add 3 hours, as Tarwn suggested, use DateAdd function, something like this:

result = DateAdd("h",3,yourDate)

Hope this help.
 
I can't use the doublequote around the h in dateadd, that's what I tried at first.. in my situation I have to use a single quote. I tried using no quotes and that didn't work either.. Also, for "now", it doesn't work for me without (), as in now().

Thanks for all the help, you people are awesome!
I've only been using tek-tips for two days now, but the help and super fast response times have been amazing!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top