Hi I am experimenting with VBScript and SQL and am unsure if the following code will actually work. I do not have access to IIS at present so I am unable to test it. I would be greatfull if anyone could just take a brief look at the code to see if the syntax is correct. Thanks
'Not needed as below. If this doesn't work (the current_timestamp), you can always use the following line and substitute it in below:
'newDateTime = now()
newMessage = Trim(Request.Form("strMessage"))
' You should always trim variables coming in to lose beginning or trailing white spaces
if newMessage <> ""then
sqlInsert="INSERT INTO tblMessages(datecreated,message) VALUES(CURRENT_TIMESTAMP,newMessage)"
endif
' Great thing about SQL, you can automatically put the date and time inside the database without having to code it in. You can set this to be default on your database, or do it from the SQL query. Change the date and time columns on your database to one. And also realize that date is probably a protected word in SQL. Use something more suitable like, datecreated.
Set objRecordSet=Server.CreateObject("ADODB.Recordset")
' You should never open the entire table like that, even if that works.. Use a select statement.
' What the formatdatetime does is take the value and format what you want out of it. there are many ways to do this. the 2 after the value just creates time as 00:00:00 PM/AM, the 3 means 00/00/0000 format.
' Also remember that whenever you are dealing with more than one row, you need to put the recordsetname.fields attribute above.
So you know, if you are using a DATETIME field in your SQL database, you use the CURRENT_TIMESTAMP to get the current date and time. If you are using just date, use CURDATE(). When retrieving your information out of your database, especially for dates, you can do it this way:
DATE_FORMAT(datecreated, '%m/%d/%Y')
this will pull something out of your datetime or date column as: 2/7/2007
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.