|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
VBScript - General - Question - Adding a time field to an asp page that saves to mysql
This is an asp page that adds news articles to an mysql database.
The form adds the time to the database. On the public side it shows 11/22/2008 12:00:00 AM which means a time isn't being entered in the database. the database is set to DATETIME with no default. DB 3 is MySQL The page that adds the the article and sends it to the database is this and this is the relevant part of the code i think, news_add.asp Code:
<%Dim MODE, MESSAGE, CATE_STR, SQL, RS, CATE, AGENT, ACTIVE, ALLOW_C, ALLOW_V, TITLE, SUMMARY, IMAGE, CONTENT, I, _
arrCATE, ID, sDATE, eDATE, TID, TEMPLATE, A_C, A_V, APPROVE, HLITE, AGENT_STR, USE_VIEW
MODE = Request.Form("mode")
TID = Trim(Request.QueryString("TID"))
Call CREATE_SECURITY()
IF NOT Trim(arrLEVEL(27)) = "1" THEN MESSAGE = "<li />Sorry, you don't have access to this section."
'
'<description> add new article to the DB </description>
'
IF MODE = "add" THEN
With Request
arrCATE = Split(APO(.Form("cate")),",")
AGENT = APO(.Form("agent"))
ACTIVE = CONVERT_NUM(.Form("active"))
ALLOW_C = CONVERT_NUM(.Form("allow_c"))
ALLOW_V = CONVERT_NUM(.Form("allow_v"))
TITLE = APO(.Form("title"))
SUMMARY = APO(STRIP_CODE(.Form("summary")))
USE_VIEW = APO(.Form("USE_VIEW"))
IMAGE = APO(.Form("image"))
CONTENT = APO_LAX(.Form("content"))
IF DB_TO_USE = 3 THEN
sDATE = .Form("sY") & "-" & .Form("sM") & "-" & .Form("sD")
eDATE = .Form("eY") & "-" & .Form("eM") & "-" & .Form("eD")
ELSE
sDATE = ASEMBLE_DATE_FORMAT(.Form("sD"),.Form("sM"),.Form("sY"))
eDATE = ASEMBLE_DATE_FORMAT(.Form("eD"),.Form("eM"),.Form("eY"))
END IF
HLITE = CONVERT_NUM(.Form("hlite"))
End With
Call CHECK_INQP()
IF MESSAGE = "" THEN
'
'<description> add article </description>
'
SQL = "INSERT INTO nm_tbl_news (fldTITLE, fldCONTENT, fldSUMMARY, fldACTIVE, fldAID, fldPOSTED, fldEXPIRES, fldIMAGE, fldALLOW_COMMENTS, fldALLOW_VOTING, fldHIGHLIGHT, fldUSE_VIEW) VALUES ('" & TITLE & "','" & CONTENT & "','" & SUMMARY & "'," & ACTIVE & "," & AGENT & ",'" & sDATE & "','" & eDATE & "','" & IMAGE & "'," & ALLOW_C & "," & ALLOW_V & "," & HLITE & ", " & USE_VIEW & ")"
END IF
I think it is to this part, where i need to add something so that there is a datefield which also adds the time to the database. Code:
IF DB_TO_USE = 3 THEN
sDATE = .Form("sY") & "-" & .Form("sM") & "-" & .Form("sD")
eDATE = .Form("eY") & "-" & .Form("eM") & "-" & .Form("eD")
can someone pls show me what to add where, and if any other code in the page would need changing too? Many thanks |
|
#2
|
|||
|
|||
|
In addition to the code above, I think i should show the actual form fields in the page that add the date.
I think it is here that i need to enter a TIME VALUE, so that in addition to the date, there would be a time field This is the part of the form that has the publish and expiry date fields, that adds the date, so i assume something needs to be added here that will pluck the time too? Just to clarify, these 2 dates below can be changed ie. an article can be set to be published at a future date, and the expiry date can be changed too. There is one other date field that is automatically added to the database which is called fldCREATED, and that is set to default at CURRENT_TIMESTAMP, the date, it was added to the database. But the code below is for the publish and expiry dates, i need to add a time field publish date code Code:
<table cellpadding="2" cellspacing="0" border="0" width="100%"><tr> <td> <table cellpadding="2" cellspacing="0" border="0"><tr> <td>Publish Date:</td> <td><select name="sM" id="sM"><%FOR I = 1 TO 12%><option<%If Trim(I) = Trim(Month(Date)) Then %> selected<%End If%> value="<%=I%>"><%=I%><%NEXT%></select></td> <td>/</td> <td><select name="sD" id="sD"><%FOR I = 1 TO 31%><option<%If Trim(I) = Trim(day(Date)) Then %> selected<%End If%> value="<%=I%>"><%=I%><%NEXT%></select></td> <td>/</td> <td><select name="sY" id="sY"><%FOR I = 2001 TO 2030%><option<%If Trim(I) = Trim(Year(Date)) Then %> selected<%End If%> value="<%=I%>"><%=I%><%NEXT%></select></td> expiry date code Code:
<table align="right" cellpadding="2" cellspacing="0" border="0"><tr> <td>Expires Date:</td> <td><select name="eM" id="eM"><%FOR I = 1 TO 12%><option<%If Trim(I) = Trim(Month(Date)) Then %> selected<%End If%> value="<%=I%>"><%=I%><%NEXT%></select></td> <td>/</td> <td id="eD"><select name="eD" id="eD"><%FOR I = 1 TO 31%><option<%If Trim(I) = Trim(Day(Date)) Then %> selected<%End If%> value="<%=I%>"><%=I%><%NEXT%></select></td> <td>/</td> <td><select name="eY" id="eY"><%FOR I = 2001 TO 2030%><option<%If Trim(I) = Trim(Year(Date+365)) Then %> selected<%End If%> value="<%=I%>"><%=I%><%NEXT%></select></td> Could anyone show me how to add a time field here so that the time also gets saved to to the database? |
|
#3
|
||||
|
||||
|
you never give any time so it's obvious that you'll see no time.
this code: Code:
sDATE = .Form("sY") & "-" & .Form("sM") & "-" & .Form("sD")
means the value that is entered to the database is the string "2008-11-22" and the database know to interpret it as November 22nd, 2008 and give default of 12:00 AM time. you need to add time fields (hour and minute) name them "sHour" and "sMinute" accordingly then have such code: Code:
eDATE = .Form("eY") & "-" & .Form("eM") & "-" & .Form("eD") & " " & .Form("eHour") & ":" & .Form("eMinute")
|
|
#4
|
|||
|
|||
|
Quote:
Thank you Shadow Wizard, Is that the only part of the code i need to change so that the time gets entered in all the fields? I will try that, In the meantime, i will say that the fldCREATED is the only one of the 3 time fields that shows the time in the database. fldCREATED doesn't need the code above for the date to show it's record in the database . Is that because it is set to TIMESTAMP in the database with a default of CURRENT_TIMESTAMP? in the database this is what fldCREATED shows 2008-11-22 18:31:54 but fldPOSTED shows 2008-11-22 00:00:00 and fldEXPIRY shows 2030-11-22 00:00:00 |
|
#5
|
||||
|
||||
|
the above code will "fix" the fied "fldEXPIRY", you'll have to do
the same for eDATE in order to fix fldPOSTED as well. the time inside fldCREATED is the time when the new record was added. it's there because of the the default value you have. |
|
#6
|
|||
|
|||
|
Quote:
ShadowWizard, i tried this code as you suggested (added minutes and hours) Code:
IF DB_TO_USE = 3 THEN
IF DB_TO_USE = 3 THEN
sDATE = .Form("sY") & "-" & .Form("sM") & "-" & .Form("sD") & " " & .Form("sHour") & ":" & .Form("sMinute")
eDATE = .Form("eY") & "-" & .Form("eM") & "-" & .Form("eD") & " " & .Form("eHour") & ":" & .Form("eMinute")
but when i try to add an article the date isn't recognised, it shows this error Please select valid publish date. Please select valid expiry date. Surely i need to add something to the form fields in the page? Thats why i posted them too, in the second post in this thread. The code you gave me altered what is actually going in the database, it's not doing anything to the form fields that are inputting the data. There are two fields, the publish date and expiry dates. I think i need to do something to these too. |
|
#7
|
||||
|
||||
|
I have no idea what's going on, post relevant code and I'll try to help
you solve this problem. |
|
#8
|
|||
|
|||
|
Quote:
This is the part of the form that has the publish and expiry date fields, that adds the date, so i assume something needs to be added here that will pluck the time too? the code below is for the publish and expiry dates, i need to add a time field to each i think publish date code Code:
<table cellpadding="2" cellspacing="0" border="0" width="100%"><tr> <td> <table cellpadding="2" cellspacing="0" border="0"><tr> <td>Publish Date:</td> <td><select name="sM" id="sM"><%FOR I = 1 TO 12%><option<%If Trim(I) = Trim(Month(Date)) Then %> selected<%End If%> value="<%=I%>"><%=I%><%NEXT%></select></td> <td>/</td> <td><select name="sD" id="sD"><%FOR I = 1 TO 31%><option<%If Trim(I) = Trim(day(Date)) Then %> selected<%End If%> value="<%=I%>"><%=I%><%NEXT%></select></td> <td>/</td> <td><select name="sY" id="sY"><%FOR I = 2001 TO 2030%><option<%If Trim(I) = Trim(Year(Date)) Then %> selected<%End If%> value="<%=I%>"><%=I%><%NEXT%></select></td> expiry date code Code:
<table align="right" cellpadding="2" cellspacing="0" border="0"><tr> <td>Expires Date:</td> <td><select name="eM" id="eM"><%FOR I = 1 TO 12%><option<%If Trim(I) = Trim(Month(Date)) Then %> selected<%End If%> value="<%=I%>"><%=I%><%NEXT%></select></td> <td>/</td> <td id="eD"><select name="eD" id="eD"><%FOR I = 1 TO 31%><option<%If Trim(I) = Trim(Day(Date)) Then %> selected<%End If%> value="<%=I%>"><%=I%><%NEXT%></select></td> <td>/</td> <td><select name="eY" id="eY"><%FOR I = 2001 TO 2030%><option<%If Trim(I) = Trim(Year(Date+365)) Then %> selected<%End If%> value="<%=I%>"><%=I%><%NEXT%></select></td> |
|
#9
|
||||
|
||||
|
indeed. add those lines for publish date:
Code:
<td><select name="sHour" id="sHour"><%FOR I = 0 TO 23%><option<%If Trim(I) = Trim(Hour(Date)) Then %> selected<%End If%> value="<%=I%>"><%=I%><%NEXT%></select></td> <td>:</td> <td><select name="sMinute" id="sMinute"><%FOR I = 0 TO 59%><option<%If Trim(I) = Trim(Minute(Date)) Then %> selected<%End If%> value="<%=I%>"><%=I%><%NEXT%></select></td> and same way add lines to expiry date. (changing the name and ID of the select) |
|
#10
|
|||
|
|||
|
Shadow Wizard, thanks, that seems to work fine The date on the public side shows 11/29/2008 12:49:00 AM I was wondering , could i add seconds too, instead of always 00 at the end? it would help in the sitemaps. One other thing, on the page that adds the article, the fields i showed you above, for the day, month and year, are automatically pointing to the current time. ( i can of course change them, and usually i only change the expiry date, to set it for a longer date than the one year it selects) I note that the new fields i added, are set to zero. ie. the hour and minutes. I added the hour and minutes manually. But i'd like it to be set to the server or other auto time. This saves a lot of time. The only thing i usually alter on these defaults is either the publishing date and always the expiry date. The hour, minute and seconds can be set automatically, and i don't think i'll be changing them usually. How can i set these so that they show the hour and minute of the server? and also the other field i want, ie. the seconds field, should also be part of the default. Here is the code on the page i'm now using, Code:
<<table cellpadding="2" cellspacing="0" border="0" width="100%"><tr>
<td>
<table cellpadding="2" cellspacing="0" border="0"><tr>
<td>Publish Date:</td>
<td><select name="sM" id="sM"><%FOR I = 1 TO 12%><option<%If Trim(I) = Trim(Month(Date)) Then %> selected<%End If%> value="<%=I%>"><%=I%><%NEXT%></select></td>
<td>/</td>
<td><select name="sD" id="sD"><%FOR I = 1 TO 31%><option<%If Trim(I) = Trim(day(Date)) Then %> selected<%End If%> value="<%=I%>"><%=I%><%NEXT%></select></td>
<td>/</td>
<td><select name="sY" id="sY"><%FOR I = 2001 TO 2030%><option<%If Trim(I) = Trim(Year(Date)) Then %> selected<%End If%> value="<%=I%>"><%=I%><%NEXT%></select></td>
<td><select name="sHour" id="sHour"><%FOR I = 0 TO 23%><option<%If Trim(I) = Trim(Hour(Date)) Then %> selected<%End If%> value="<%=I%>"><%=I%><%NEXT%></select></td>
<td>:</td>
<td><select name="sMinute" id="sMinute"><%FOR I = 0 TO 59%><option<%If Trim(I) = Trim(Minute(Date)) Then %> selected<%End If%> value="<%=I%>"><%=I%><%NEXT%></select></td>
td><A HREF="#" onClick="cal15.showCalendar('anchor15',getDateString(docume nt.forms[0].sY,document.forms[0].sM,document.forms[0].sD)); return false;" TITLE="cal15.showCalendar('anchor15',getDateString(docume nt.forms[0].sY,document.forms[0].sM,document.forms[0].sD)); return false;" NAME="anchor15" ID="anchor15"><img src="images/calendar_pick.gif" width="16" height="16" alt="Select date ..." border="0" /></A></td>
</tr></table>
</td>
<td>
<table align="right" cellpadding="2" cellspacing="0" border="0"><tr>
<td>Expires Date:</td>
<td><select name="eM" id="eM"><%FOR I = 1 TO 12%><option<%If Trim(I) = Trim(Month(Date)) Then %> selected<%End If%> value="<%=I%>"><%=I%><%NEXT%></select></td>
<td>/</td>
<td id="eD"><select name="eD" id="eD"><%FOR I = 1 TO 31%><option<%If Trim(I) = Trim(Day(Date)) Then %> selected<%End If%> value="<%=I%>"><%=I%><%NEXT%></select></td>
<td>/</td>
<td><select name="eY" id="eY"><%FOR I = 2001 TO 2030%><option<%If Trim(I) = Trim(Year(Date+365)) Then %> selected<%End If%> value="<%=I%>"><%=I%><%NEXT%></select></td>
<td><select name="eHour" id="eHour"><%FOR I = 0 TO 23%><option<%If Trim(I) = Trim(Hour(Date)) Then %> selected<%End If%> value="<%=I%>"><%=I%><%NEXT%></select></td>
<td>:</td>
<td><select name="eMinute" id="eMinute"><%FOR I = 0 TO 59%><option<%If Trim(I) = Trim(Minute(Date)) Then %> selected<%End If%> value="<%=I%>"><%=I%><%NEXT%></select></td>
<td><A HREF="#" onClick="cal20.showCalendar('anchor20',getDateString(docume nt.forms[0].eY,document.forms[0].eM,document.forms[0].eD)); return false;" TITLE="cal20.showCalendar('anchor20',getDateString(docume nt.forms[0].eY,document.forms[0].eM,document.forms[0].eD)); return false;" NAME="anchor20" ID="anchor20"><img src="images/calendar_pick.gif" width="16" height="16" alt="Select date ..." border="0" /></A></td>
</tr></table>
</td>
</tr></table>
</td>
</tr>
<tr><td colspan="2"><br /><br /></td></tr>
<tr>
<td>Article Title:</td>
<td align="right"><input type="Text" name="title" value="" maxlength="85" size="60" style="width: 450px;" class="textbox" /></td>
</tr><tr>
<td valign="top">Article Summary:</td>
<td align="right"><textarea rows="2" cols="64" name="summary" class="textbox" style="width:450px;"></textarea></td>
</tr><tr>
<td>Article Image URL:</td>
<td align="right"><input type="Text" name="image" value="" maxlength="255" size="60" style="width: 408px;" class="textbox" /> <a href="f_manager.asp?gateway=ArticleImage" onClick="NewWindow(this.href,'name','515','320','No');retur n false;"><img src="images/src.gif" width="16" height="16" alt="Select Image ..." border="0" /></a> <a href="#" onClick="return ValidateImageNews(frm.image.value);"><img src="images/ico_open_url.gif" width="18" height="15" alt="Preview URL" border="0"></a>
and here is some other code on the page . I did't include the javascript calender call code, which is in a separate file, Code:
'<description> Check the input content </description>
'
SUB CHECK_INP()
IF Ubound(arrCATE) = -1 THEN MESSAGE = MESSAGE & "<li />Please select at least one category for the article."
IF TITLE = "" OR IsNUll(TITLE) THEN MESSAGE = MESSAGE & "<li />Please enter article title."
IF SUMMARY = "" OR IsNUll(SUMMARY) THEN MESSAGE = MESSAGE & "<li />Please enter article summary."
IF CONTENT = "" OR IsNUll(CONTENT) THEN MESSAGE = MESSAGE & "<li />Please enter article content."
IF IsDate(sDATE) = False THEN MESSAGE = MESSAGE & "< |