By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,549 Members | 1,717 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,549 IT Pros & Developers. It's quick & easy.

After transferring to MySQL, date fieldvalues now show null

P: 20
I have a news website, with asp pages, which was on Access, and i upgraded to MySQL, i used Bullzip to transfer the data. It had about 1000 pages, which im now able to pull up on the public side. Im sorting out a few glitches though.

Since i upgraded from ms access database to MySQL, i have added about 4 articles to test the new setup. I note some fields aren't being added in the new mySql database for the new 4 records. When i ran the MySQK query analyser and checked to see what was in the database fields.. the "fldCreated" shows NULL, when it should be showing a date. In the query analyser, the dates BEFORE the new mysql database show:

nm_tbl_news n;
2008-10-15 08:28:31


but in the few articles i added after the transfer it doesn't have a date, it says NULL, which means the code adding the date to the database must be wrong.


I'm including some code from the newsadd.asp page, which is the page that is actually adding the news to the database and also some code from the include files on this page , which may be relevant


inc_api.asp
[code]
Expand|Select|Wrap|Line Numbers
  1. FUNCTION RFC822(dDate,iOffset)
  2.     Dim d
  3.     d = DateAdd("h",-iOffset,dDate)
  4.     RFC822 = Left(WeekDayName(WeekDay(d)),3) & ", " & Right(String(2,"0") & Day(d),2) & " " & Left(MonthName(Month(d)),3) & " " & Year(d) & " " & Right(String(2,"0") & Hour(d),2) & ":" & Right(String(2,"0") & Minute(d),2) & ":" & Right(String(2,"0") & Second(d),2) & " " & "GMT"
  5. END FUNCTION    



config.asp
Expand|Select|Wrap|Line Numbers
  1. <% Dim MyConn, APPLICATION_URL, arrLEVEL, SAFE_EXTENSIONS_ONLY, KEEP_LOGS, DB_TO_USE, ALL_ARTICLES_PAGE_SIZE, SET_EMAIL_COMP, SHOW_AUTHOR
  2.    Dim SEARCH_METHOD, SEARCH_IN, SEARCH_MODE, SEARCH_FOR
  3.  
  4.    Session.LCID = 1033
  5.  
  6.  
  7.  
  8.         ' Set to 1 if you are using MS Access, set to 2 if you are using MS SQL database, 3 for MySQL
  9.         DB_TO_USE = 3
  10.  
  11.  
  12.     ' Assemble date value
  13.     FUNCTION ASEMBLE_DATE_FORMAT(sDAY, sMONTH, sYEAR)
  14.         Dim DATE_FORMAT, sDATE                   
  15.  
  16.         DATE_FORMAT = 1 ' US Locale
  17.  
  18.         SELECT CASE DATE_FORMAT
  19.             CASE 1
  20.                 sDATE = sMONTH & "/" & sDAY  & "/" & sYEAR
  21.             CASE ELSE
  22.                 sDATE = sMONTH & "/" & sDAY  & "/" & sYEAR
  23.         END SELECT            
  24.         ASEMBLE_DATE_FORMAT = sDATE
  25.     END FUNCTION
  26.  
  27.  
  28.  
  29.     <% '// NO NEED TO MODIFY ANYTHING BELOW 
  30. FUNCTION CNT_DATE(sDATE)
  31.   IF IsDate(sDATE) = True THEN
  32.  
  33.     SELECT CASE DATE_FORMAT
  34.         CASE 1        'YYYYMMDD
  35.             CNT_DATE = Year(sDATE) & Right(Cstr(Month(sDATE) + 100),2) & Right(Cstr(Day(sDATE) + 100),2)
  36.         CASE 2        'YYYY-MM-DD
  37.             CNT_DATE = Year(sDATE) & "-" & Right(Cstr(Month(sDATE) + 100),2) & "-" & Right(Cstr(Day(sDATE) + 100),2)
  38.         CASE 101    'mm/dd/yy 
  39.             CNT_DATE = Right(Cstr(Month(sDATE) + 100),2) & "/" & Right(Cstr(Day(sDATE) + 100),2) & "/" & Right(Cstr(Year(sDATE)),2)
  40.         CASE 102    'yy.mm.dd
  41.             CNT_DATE = Right(Cstr(Year(sDATE)),2) & "." & Right(Cstr(Month(sDATE) + 100),2) & "." & Right(Cstr(Day(sDATE) + 100),2)
  42.         CASE 103    'dd/mm/yy
  43.             CNT_DATE = Right(Cstr(Day(sDATE) + 100),2) & "/" & Right(Cstr(Month(sDATE) + 100),2) & "/" & Right(Cstr(Year(sDATE)),2)
  44.         CASE 104    'dd.mm.yy
  45.             CNT_DATE = Right(Cstr(Day(sDATE) + 100),2) & "." & Right(Cstr(Month(sDATE) + 100),2) & "." & Right(Cstr(Year(sDATE)),2)
  46.         CASE 105    'dd-mm-yy
  47.             CNT_DATE = Right(Cstr(Day(sDATE) + 100),2) & "-" & Right(Cstr(Month(sDATE) + 100),2) & "-" & Right(Cstr(Year(sDATE)),2)
  48.         CASE 110    'mm-dd-yy
  49.             CNT_DATE = Right(Cstr(Month(sDATE) + 100),2) & "-" & Right(Cstr(Day(sDATE) + 100),2) & "-" & Right(Cstr(Year(sDATE)),2)
  50.         CASE 111    'yy/mm/dd
  51.             CNT_DATE = Right(Cstr(Year(sDATE)),2) & "/" & Right(Cstr(Month(sDATE) + 100),2) & "/" & Right(Cstr(Day(sDATE) + 100),2)    
  52.         CASE 112    'yymmdd
  53.             CNT_DATE = Right(Cstr(Year(sDATE)),2) & Right(Cstr(Month(sDATE) + 100),2) & Right(Cstr(Day(sDATE) + 100),2)
  54.     END SELECT    
  55.   ELSE
  56.       CNT_DATE = Null
  57.   END IF
  58. END FUNCTION
  59. %>    

and this is the page that adds the news to the database, ive tried to only include relevant code, (or that which i think is relevant) as it is a long page, .

newsadd.asp
Expand|Select|Wrap|Line Numbers
  1. <!--#include file="inc_api.asp"-->
  2. <!--#include file="config.asp"-->
  3.  
  4.     <%Dim MODE, MESSAGE, CATE_STR, SQL, RS, CATE, AGENT, ACTIVE, ALLOW_C, ALLOW_V, TITLE, SUMMARY, IMAGE, CONTENT, I, _
  5.           arrCATE, ID, sDATE, eDATE, TID, TEMPLATE, A_C, A_V, APPROVE, HLITE, AGENT_STR, USE_VIEW
  6.  
  7.     MODE = Request.Form("mode")
  8.     TID  = Trim(Request.QueryString("TID"))
  9.  
  10.  
  11.     Call CREATE_SECURITY()    
  12.     IF NOT Trim(arrLEVEL(27)) = "1" THEN MESSAGE = "<li />Sorry, you don't have access to this section."    
  13.  
  14.     '
  15.     '<description> add new article to the DB </description>
  16.     '
  17.     IF MODE = "add" THEN
  18.  
  19.         With Request
  20.             arrCATE     = Split(APO(.Form("cate")),",")
  21.             AGENT    = APO(.Form("agent"))
  22.             ACTIVE   = CONVERT_NUM(.Form("active"))
  23.             ALLOW_C  = CONVERT_NUM(.Form("allow_c"))
  24.             ALLOW_V  = CONVERT_NUM(.Form("allow_v"))
  25.             TITLE    = APO(.Form("title"))
  26.             SUMMARY  = APO(STRIP_CODE(.Form("summary")))
  27.             USE_VIEW = APO(.Form("USE_VIEW"))
  28.             IMAGE    = APO(.Form("image"))            
  29.             CONTENT  = APO_LAX(.Form("content"))            
  30.             IF DB_TO_USE = 3 THEN
  31.                 sDATE = .Form("sY") & "-" & .Form("sM") & "-" & .Form("sD")    
  32.                 eDATE = .Form("eY") & "-" & .Form("eM") & "-" & .Form("eD")    
  33.             ELSE
  34.                 sDATE    = ASEMBLE_DATE_FORMAT(.Form("sD"),.Form("sM"),.Form("sY"))
  35.                 eDATE    = ASEMBLE_DATE_FORMAT(.Form("eD"),.Form("eM"),.Form("eY"))  
  36.             END IF  
  37.             HLITE    = CONVERT_NUM(.Form("hlite"))
  38.         End With
  39.  
  40.         Call CHECK_INP()        
  41.  
  42.         IF MESSAGE = "" THEN            
  43.             '
  44.             '<description> add article </description>
  45.             '               
  46.                      ELSE
  47.                 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 & ")"
  48.             END IF                
  49.             Call OPEN_DB()
  50.  
  51.             MyConn.Execute SQL
  52.  
  53.             SQL = "SELECT ID FROM nm_tbl_news WHERE fldTITLE='" & TITLE & "' AND fldAID = " & AGENT & " ORDER BY ID DESC"
  54.             Set RS = Server.CreateObject("ADODB.Recordset")
  55.             RS.Open SQL, MyConn    
  56.                  IF NOT RS.EOF THEN
  57.                      ID = trim(RS("ID"))
  58.                  END IF
  59.             RS.Close 
  60.  
  61.             '
  62.             '<description> add category association </description>
  63.             '              
  64.             FOR I = 0 to Ubound(arrCATE)
  65.                 IF IS_VALID_ID(Trim(arrCATE(I))) = True THEN
  66.                     SQL = "INSERT INTO nm_tbl_news_cate (fldNEWS_ID, fldCATE_ID) VALUES (" & ID & "," & Trim(arrCATE(I)) & ")"
  67.                     MyConn.Execute SQL
  68.                 END IF    
  69.             NEXT 
  70.  
  71.             ' { Append New Log Lin } 
  72.             Call APPEND_LOG(False, "Added new article ( " & TITLE & " ).", Session("ID"))            
  73.  
  74.             MyConn.close 
  75.             Set MyConn = Nothing                                    
  76.  
  77.             Response.Redirect "news.asp"
  78.             Response.End
  79.         END IF
  80.  
  81.     ELSE
  82.  
  83.         Call OPEN_DB()
  84.         '
  85.         '<description> Create the category drop down </description>
  86.         '        
  87.  
  88.         IF DB_TO_USE = 3 THEN
  89.             SQL = "SELECT ID, fldNAME, ID as ID1, 0 as ID2, 0 as ID3 FROM nm_tbl_cate WHERE fldLEVEL = 1 UNION SELECT nm_tbl_cate.ID, CONCAT(PARENT.fldNAME , ' > ' , nm_tbl_cate.fldNAME) AS NAME, PARENT.id, nm_tbl_cate.ID, 0 FROM nm_tbl_cate, nm_tbl_cate AS PARENT WHERE (nm_tbl_cate.fldLEVEL = 2) AND (nm_tbl_cate.fldPID =PARENT.ID) UNION SELECT nm_tbl_cate.ID, CONCAT(PARENT.fldNAME , ' > ' , SUBPARENT.fldNAME , ' > ' , nm_tbl_cate.fldNAME) AS NAME, PARENT.id, SUBPARENT.id, nm_tbl_cate.ID FROM nm_tbl_cate, nm_tbl_cate AS PARENT, nm_tbl_cate AS SUBPARENT  WHERE (nm_tbl_cate.fldLEVEL = 3) AND (nm_tbl_cate.fldPID =PARENT.ID) AND (nm_tbl_cate.fldSID =SUBPARENT.ID) ORDER BY `fldName` ASC"
  90.         ELSE        
  91.                     END IF            
  92.         Set RS = Server.CreateObject("ADODB.Recordset")
  93.         RS.LockType   = 1
  94.         RS.CursorType = 0
  95.  
  96.  
  97.         RS.Open SQL, MyConn    
  98.              WHILE NOT RS.EOF 
  99.                 CATE_STR = CATE_STR & "<option value='" & trim(RS("ID")) & "'>" & trim(RS("fldNAME")) & vbcrlf
  100.                 RS.MoveNext
  101.              WEND
  102.         RS.Close 
  103.         '
  104.  
  105.                 ELSE
  106.                     IF Session("ID") = trim(RS("ID")) THEN
  107.                         AGENT_STR = AGENT_STR & "<option selected='selected' style='background-color: #ffffea' value='" & trim(RS("ID")) & "'>" & trim(RS("fldNAME")) & vbcrlf
  108.                     END IF                
  109.                 END IF
  110.                 RS.MoveNext
  111.              WEND
  112.         RS.Close
  113.  
  114.         IF IS_VALID_ID(TID) THEN 
  115.  
  116.             SQL = "SELECT fldTEMPLATE FROM nm_tbl_template WHERE ID = " & TID
  117.             Set RS = Server.CreateObject("ADODB.Recordset")
  118.             RS.LockType   = 1
  119.             RS.CursorType = 0
  120.             RS.Open SQL, MyConn    
  121.                  IF NOT RS.EOF THEN
  122.                      TEMPLATE = trim(RS("fldTEMPLATE"))
  123.                  END IF
  124.             RS.Close     
  125.  
  126.         END IF           
  127.  
  128.         SQL = "SELECT fldA_V, fldA_C, fldAPPROVE FROM nm_tbl_settings WHERE ID = 1"
  129.         Set RS = Server.CreateObject("ADODB.Recordset")
  130.         RS.LockType   = 1
  131.         RS.CursorType = 0
  132.         RS.Open SQL, MyConn    
  133.              IF NOT RS.EOF THEN
  134.                 A_C     = Trim(RS("fldA_C"))
  135.                 A_V     = Trim(RS("fldA_V"))
  136.                 APPROVE = Trim(RS("fldAPPROVE"))
  137.              END IF
  138.         RS.Close 
  139.  
  140.         Set RS = Nothing        
  141.         MyConn.Close
  142.         Set MyConn = Nothing
  143.  
  144.     END IF    
  145.  
  146.  
  147.     %>
  148.  
  149.  
  150.  
  151.     <table width="100%" align="center" cellpadding="2" cellspacing="0" border="0">
  152.         <tr>
  153.  
  154.         </tr>
  155.     </table>
  156.     <br />
  157.     <table width="100%" align="center" cellpadding="2" cellspacing="0" border="1" bordercolor="whitesmoke" style="border-collapse: collapse;">
  158.         <tr bgcolor="whitesmoke">
  159.             <td class="MainTitle">Add New Article</td>
  160.             <td class="MainTitle" align="right">< <a href="templates.asp">Apply Template</a> ></td>
  161.         </tr>
  162.         <tr>
  163.             <td colspan="2">
  164.                 <br />       
  165.  
  166.                 <form action="newsadd.asp" method="post" name="frm">
  167.                 <table cellpadding="2" cellspacing="0" border="0" align="center" width="622">
  168.                     <tr>
  169.                         <td>Article&nbsp;By:</td>
  170.                         <td align="right"><select name="agent" class="textbox" style="width: 450px;"><%= AGENT_STR %></select></td>
  171.                     </tr>
  172.                     <tr>
  173.  
  174.                                                                <td>Publish Date:</td>
  175.                                         <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>
  176.                                         <td>/</td>
  177.                                         <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>
  178.                                         <td>/</td>
  179.                                         <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>
  180.                                         <td></td>
  181.                                     </tr></table>        
  182.                                 </td>
  183.                                 <td>
  184.                                     <table align="right" cellpadding="2" cellspacing="0" border="0"><tr>
  185.                                         <td>Expires Date:</td>
  186.                                         <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>
  187.                                         <td>/</td>
  188.                                         <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>
  189.                                         <td>/</td>
  190.                                         <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>
  191.                                         <td></td>
  192.                                     </tr></table>        
  193.                                 </td>
  194.                             </tr></table>
  195.  
  196.                         </td>                    
  197.                     </tr>                    
  198.  
  199.                         </td>
  200.                     </tr><tr>
  201.                         <td colspan="2" align="right"><br /><input type="Submit" value="Add Article" onClick="return ValidateNewsArticle()" /><br /></td>
  202.                     </tr></table>                                
  203.                 <input type="Hidden" name="mode" value="add" />
  204.                 </form>
  205.                 <br /><br />
  206.             </td>
  207.         </tr>
  208.     </table>    
  209.  
  210. <!--#include file="inc_footer.asp"-->
I'd appreciate it if anyone could show me what to change and where. I'm not html literate, and realise the code above is probably not written in the best way, but im just concerned with getting it to function.

Much appreciated and thanks in advance
Nov 16 '08 #1
Share this Question
Share on Google+
3 Replies


Expert 100+
P: 164
On line 47 of your news_add.asp, there is no reference to a "fldCreated" in your SQL query. That means no value would be input to your table when this script fires off.

I have modified your file with important changes. See lines 18 - 23.

I created a new variable 'CREATE_DATE'.

The code on line 21 formats this date as "MM/DD/YYY"

Line 22 is just so I can get around modifying other files and thus complicating this for you.

Line 23 formats the date for MySQL insertion.

Skip to line 53 now. It now includes fldCreated.

Try this and let me know if it works.

Expand|Select|Wrap|Line Numbers
  1. <!--#include file="inc_api.asp"--> 
  2. <!--#include file="config.asp"--> 
  3.  
  4.     <%Dim MODE, MESSAGE, CATE_STR, SQL, RS, CATE, AGENT, ACTIVE, ALLOW_C, ALLOW_V, TITLE, SUMMARY, IMAGE, CONTENT, I, _ 
  5.           arrCATE, ID, sDATE, eDATE, TID, TEMPLATE, A_C, A_V, APPROVE, HLITE, AGENT_STR, USE_VIEW 
  6.  
  7.     MODE = Request.Form("mode") 
  8.     TID  = Trim(Request.QueryString("TID")) 
  9.  
  10.  
  11.     Call CREATE_SECURITY()     
  12.     IF NOT Trim(arrLEVEL(27)) = "1" THEN MESSAGE = "<li />Sorry, you don't have access to this section."     
  13.  
  14.     ' 
  15.     '<description> add new article to the DB </description> 
  16.     ' 
  17.     IF MODE = "add" THEN 
  18.         ''// added by nicodemas
  19.         twoDay      = day(date) :   if twoDay < 10 then twoDay = "0" & twoDay
  20.         twoMonth    = month(date) : if twoMonth < 10 then twoMonth = "0" & twoMonth
  21.         CREATE_DATE = ASEMBLE_DATE_FORMAT(twoDay,twoMonth,year(date)) 
  22.         DATE_FORMAT = 2
  23.         CREATE_DATE = CNT_DATE(CREATE_DATE)
  24.  
  25.         With Request 
  26.             arrCATE     = Split(APO(.Form("cate")),",") 
  27.             AGENT    = APO(.Form("agent")) 
  28.             ACTIVE   = CONVERT_NUM(.Form("active")) 
  29.             ALLOW_C  = CONVERT_NUM(.Form("allow_c")) 
  30.             ALLOW_V  = CONVERT_NUM(.Form("allow_v")) 
  31.             TITLE    = APO(.Form("title")) 
  32.             SUMMARY  = APO(STRIP_CODE(.Form("summary"))) 
  33.             USE_VIEW = APO(.Form("USE_VIEW")) 
  34.             IMAGE    = APO(.Form("image"))             
  35.             CONTENT  = APO_LAX(.Form("content"))             
  36.             IF DB_TO_USE = 3 THEN 
  37.                 sDATE = .Form("sY") & "-" & .Form("sM") & "-" & .Form("sD")     
  38.                 eDATE = .Form("eY") & "-" & .Form("eM") & "-" & .Form("eD")     
  39.             ELSE 
  40.                 sDATE    = ASEMBLE_DATE_FORMAT(.Form("sD"),.Form("sM"),.Form("sY")) 
  41.                 eDATE    = ASEMBLE_DATE_FORMAT(.Form("eD"),.Form("eM"),.Form("eY"))   
  42.             END IF   
  43.             HLITE    = CONVERT_NUM(.Form("hlite")) 
  44.         End With 
  45.  
  46.         Call CHECK_INP()         
  47.  
  48.         IF MESSAGE = "" THEN             
  49.             ' 
  50.             '<description> add article </description> 
  51.             '                
  52.                      ELSE 
  53.                 SQL = "INSERT INTO nm_tbl_news (fldCreated, fldTITLE, fldCONTENT, fldSUMMARY, fldACTIVE, fldAID, fldPOSTED, fldEXPIRES, fldIMAGE, fldALLOW_COMMENTS, fldALLOW_VOTING, fldHIGHLIGHT, fldUSE_VIEW) VALUES ('"& CREATE_DATE &"', '" & TITLE & "','" & CONTENT & "','" & SUMMARY & "'," & ACTIVE & "," & AGENT & ",'" & sDATE & "','" & eDATE & "','" & IMAGE & "'," & ALLOW_C & "," & ALLOW_V & "," & HLITE & ", " & USE_VIEW & ")" 
  54.             END IF                 
  55.             Call OPEN_DB() 
  56.  
  57.             MyConn.Execute SQL 
  58.  
  59.             SQL = "SELECT ID FROM nm_tbl_news WHERE fldTITLE='" & TITLE & "' AND fldAID = " & AGENT & " ORDER BY ID DESC" 
  60.             Set RS = Server.CreateObject("ADODB.Recordset") 
  61.             RS.Open SQL, MyConn     
  62.                  IF NOT RS.EOF THEN 
  63.                      ID = trim(RS("ID")) 
  64.                  END IF 
  65.             RS.Close  
  66.  
  67.             ' 
  68.             '<description> add category association </description> 
  69.             '               
  70.             FOR I = 0 to Ubound(arrCATE) 
  71.                 IF IS_VALID_ID(Trim(arrCATE(I))) = True THEN 
  72.                     SQL = "INSERT INTO nm_tbl_news_cate (fldNEWS_ID, fldCATE_ID) VALUES (" & ID & "," & Trim(arrCATE(I)) & ")" 
  73.                     MyConn.Execute SQL 
  74.                 END IF     
  75.             NEXT  
  76.  
  77.             ' { Append New Log Lin }  
  78.             Call APPEND_LOG(False, "Added new article ( " & TITLE & " ).", Session("ID"))             
  79.  
  80.             MyConn.close  
  81.             Set MyConn = Nothing                                     
  82.  
  83.             Response.Redirect "news.asp" 
  84.             Response.End 
  85.         END IF 
  86.  
  87.     ELSE 
  88.  
  89.         Call OPEN_DB() 
  90.         ' 
  91.         '<description> Create the category drop down </description> 
  92.         '         
  93.  
  94.         IF DB_TO_USE = 3 THEN 
  95.             SQL = "SELECT ID, fldNAME, ID as ID1, 0 as ID2, 0 as ID3 FROM nm_tbl_cate WHERE fldLEVEL = 1 UNION SELECT nm_tbl_cate.ID, CONCAT(PARENT.fldNAME , ' > ' , nm_tbl_cate.fldNAME) AS NAME, PARENT.id, nm_tbl_cate.ID, 0 FROM nm_tbl_cate, nm_tbl_cate AS PARENT WHERE (nm_tbl_cate.fldLEVEL = 2) AND (nm_tbl_cate.fldPID =PARENT.ID) UNION SELECT nm_tbl_cate.ID, CONCAT(PARENT.fldNAME , ' > ' , SUBPARENT.fldNAME , ' > ' , nm_tbl_cate.fldNAME) AS NAME, PARENT.id, SUBPARENT.id, nm_tbl_cate.ID FROM nm_tbl_cate, nm_tbl_cate AS PARENT, nm_tbl_cate AS SUBPARENT  WHERE (nm_tbl_cate.fldLEVEL = 3) AND (nm_tbl_cate.fldPID =PARENT.ID) AND (nm_tbl_cate.fldSID =SUBPARENT.ID) ORDER BY `fldName` ASC" 
  96.         ELSE         
  97.                     END IF             
  98.         Set RS = Server.CreateObject("ADODB.Recordset") 
  99.         RS.LockType   = 1 
  100.         RS.CursorType = 0 
  101.  
  102.  
  103.         RS.Open SQL, MyConn     
  104.              WHILE NOT RS.EOF  
  105.                 CATE_STR = CATE_STR & "<option value='" & trim(RS("ID")) & "'>" & trim(RS("fldNAME")) & vbcrlf 
  106.                 RS.MoveNext 
  107.              WEND 
  108.         RS.Close  
  109.         ' 
  110.  
  111.                 ELSE 
  112.                     IF Session("ID") = trim(RS("ID")) THEN 
  113.                         AGENT_STR = AGENT_STR & "<option selected='selected' style='background-color: #ffffea' value='" & trim(RS("ID")) & "'>" & trim(RS("fldNAME")) & vbcrlf 
  114.                     END IF                 
  115.                 END IF 
  116.                 RS.MoveNext 
  117.              WEND 
  118.         RS.Close 
  119.  
  120.         IF IS_VALID_ID(TID) THEN  
  121.  
  122.             SQL = "SELECT fldTEMPLATE FROM nm_tbl_template WHERE ID = " & TID 
  123.             Set RS = Server.CreateObject("ADODB.Recordset") 
  124.             RS.LockType   = 1 
  125.             RS.CursorType = 0 
  126.             RS.Open SQL, MyConn     
  127.                  IF NOT RS.EOF THEN 
  128.                      TEMPLATE = trim(RS("fldTEMPLATE")) 
  129.                  END IF 
  130.             RS.Close      
  131.  
  132.         END IF            
  133.  
  134.         SQL = "SELECT fldA_V, fldA_C, fldAPPROVE FROM nm_tbl_settings WHERE ID = 1" 
  135.         Set RS = Server.CreateObject("ADODB.Recordset") 
  136.         RS.LockType   = 1 
  137.         RS.CursorType = 0 
  138.         RS.Open SQL, MyConn     
  139.              IF NOT RS.EOF THEN 
  140.                 A_C     = Trim(RS("fldA_C")) 
  141.                 A_V     = Trim(RS("fldA_V")) 
  142.                 APPROVE = Trim(RS("fldAPPROVE")) 
  143.              END IF 
  144.         RS.Close  
  145.  
  146.         Set RS = Nothing         
  147.         MyConn.Close 
  148.         Set MyConn = Nothing 
  149.  
  150.     END IF     
  151.  
  152.  
  153.     %> 
  154.  
  155.  
  156.  
  157.     <table width="100%" align="center" cellpadding="2" cellspacing="0" border="0"> 
  158.         <tr> 
  159.  
  160.         </tr> 
  161.     </table> 
  162.     <br /> 
  163.     <table width="100%" align="center" cellpadding="2" cellspacing="0" border="1" bordercolor="whitesmoke" style="border-collapse: collapse;"> 
  164.         <tr bgcolor="whitesmoke"> 
  165.             <td class="MainTitle">Add New Article</td> 
  166.             <td class="MainTitle" align="right">< <a href="templates.asp">Apply Template</a> ></td> 
  167.         </tr> 
  168.         <tr> 
  169.             <td colspan="2"> 
  170.                 <br />        
  171.  
  172.                 <form action="newsadd.asp" method="post" name="frm"> 
  173.                 <table cellpadding="2" cellspacing="0" border="0" align="center" width="622"> 
  174.                     <tr> 
  175.                         <td>Article&nbsp;By:</td> 
  176.                         <td align="right"><select name="agent" class="textbox" style="width: 450px;"><%= AGENT_STR %></select></td> 
  177.                     </tr> 
  178.                     <tr> 
  179.  
  180.                                                                <td>Publish Date:</td> 
  181.                                         <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> 
  182.                                         <td>/</td> 
  183.                                         <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> 
  184.                                         <td>/</td> 
  185.                                         <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> 
  186.                                         <td></td> 
  187.                                     </tr></table>         
  188.                                 </td> 
  189.                                 <td> 
  190.                                     <table align="right" cellpadding="2" cellspacing="0" border="0"><tr> 
  191.                                         <td>Expires Date:</td> 
  192.                                         <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> 
  193.                                         <td>/</td> 
  194.                                         <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> 
  195.                                         <td>/</td> 
  196.                                         <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> 
  197.                                         <td></td> 
  198.                                     </tr></table>         
  199.                                 </td> 
  200.                             </tr></table> 
  201.  
  202.                         </td>                     
  203.                     </tr>                     
  204.  
  205.                         </td> 
  206.                     </tr><tr> 
  207.                         <td colspan="2" align="right"><br /><input type="Submit" value="Add Article" onClick="return ValidateNewsArticle()" /><br /></td> 
  208.                     </tr></table>                                 
  209.                 <input type="Hidden" name="mode" value="add" /> 
  210.                 </form> 
  211.                 <br /><br /> 
  212.             </td> 
  213.         </tr> 
  214.     </table>     
  215.  
  216. <!--#include file="inc_footer.asp"--> 
Nov 17 '08 #2

P: 20
Thanks so much, N

I tried the code and when i tried adding the article i got this error message. Remember before i could add the article , but there was no date in the fldCreated showing in the Mysql database


Microsoft VBScript runtime error '800a01f4'

Variable is undefined: 'twoDay'

/Admin/ne_add.asp, line 19


and the code on line 19 is

Expand|Select|Wrap|Line Numbers
  1. With Request
Anyhow i think it important to mention something, this script was set to run on different databases, 1 for Access, 2 for MS sql and 3 for MySQL

It was working fine on Access. But i didn't show you the part for the Access database
You said " fldCreated" was missing. But it was also missing from the code used for Access, and it worked fine then. Let me show you, the complete code for that part, as i only showed you the MySQL one,

Expand|Select|Wrap|Line Numbers
  1.  '<description> add article </description>
  2.             '               
  3.             IF DB_TO_USE = 1 THEN
  4.                 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 & ")"
  5.             ELSE
  6.                 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 & ")"
  7.  
  8.             END IF 


As you can see, fldCreated was missing from the Access one too. But the data that i transferred using Bullzip, shows the fldCreated field with dates in. The only ones showing "null" are the 4 articles i added since ive had MySQL

Anyway, using the code above, it didn't add the article to the database, but returned the error above.

I don't think this is related, but when i transferred the data, i couldn't transfer using Bullzip, without leaving out the "default" values, whatever those are. When i unchecked that box, i could transfer the data. I don't think that has anything to do with this, but just in case, i thought i'd let you know.


an update: I just checked my access database, and it didn't have a "fldCreated" column, so i'm confused now. Did the transfer create this extra column or what?

Many thanks
Nov 17 '08 #3

Expert 100+
P: 164
to solve the variable undefined errors, just create Dim statements for all teh variables I added to the top of the page, underneath the include statements.
See if that clears up the issue
Dec 25 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.