Code for storing pages in a db?

Last post 05-19-2004, 2:39 PM by ucjb. 4 replies.
Sort Posts: Previous Next
  •  05-14-2004, 11:13 AM 841

    Code for storing pages in a db?

    Could someone please post the code that displays the pages in the editor and the code that saves the pages to the DB?

     

    Thanks, Jimmy

  •  05-15-2004, 12:19 PM 846 in reply to 841

    Re: Code for storing pages in a db?

    I have the code for using CuteEditor with an Access 2000 database built around Dreamweaver MX. Would that help?
  •  05-17-2004, 9:09 AM 855 in reply to 846

    Re: Code for storing pages in a db?

    That would be great!
  •  05-19-2004, 11:04 AM 864 in reply to 855

    Re: Code for storing pages in a db?

    word of warning if you are building web sites with MS access backends, if you host them on a server running windows 2003 you will come unstuck as there is a  known JET bug with ASP, MS Access and win 2003. Microsoft know about it but as yet have done NOTHING about it. It cuases IIS to HANG!!!!!!

     

    I learnt the hard way as I migrated all my hosting customers over and its been a pig converting them all over to MySQL....

     

  •  05-19-2004, 2:39 PM 869 in reply to 855

    Re: Code for storing pages in a db?

    This is the code I have for saving pages to a DB. I modified the todatabase.asp and added a couple of fields to the test.mdb. This ain't the tightest code but it works.

    <html>
        <head>
            <title>CuteEditor :  Add the editor content to the database</title>       
            <link href="example.css" type="text/css" rel="stylesheet">
        </head>
        <body>
    <form name="theForm" action="todatabase.asp" method="post" ID="Form1">
    <TABLE cellSpacing=0 cellPadding=0 width="100%" align=center border=0 ID="Table1">
    <TR><TD class=ContentBg vAlign=top height=480><BR><TABLE cellSpacing=0 cellPadding=4 width="100%" align=center border=0 ID="Table2">
    <TR><TD id=ContentPane width=* vAlign=top bgcolor=white>
    <%
     dim conn
     dim connstr
     dim filename
     Set conn = Server.CreateObject("ADODB.Connection")
     connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("webdb.mdb")
     conn.Open connstr
     dim content
     if Request.Form("del") <> "" Then
      sdelrec = "true"
      delrec()
     end if  
     if Request.Form("add") <> "" then
    %>
     <input type=hidden value="add" name=addnew>
    <%
     end if
     if Request.Form("newfile") <> "" then
      addnew()
     end if
     
     if Request.Form("filename3") <> "0" and Request.Form("filename2") = "0" and Request.Form("newfile") = "" and Request.Form("add") = "" and sdelrec = "" then
      updatefile()
     end if
    %>
    <table width="100%" cellspacing="1" cellpadding="5" border="0"><tr valign="top"><td nowrap>Select Page:</td><td>
     <SELECT NAME="filename2" size=1 onchange=theForm.submit()>
     <OPTION VALUE=0>Select A Page
    <%
     loadsel()
     sub loadsel()
      MySQL="select id, Filename from webdb"
      set rs2=conn.execute(MySQL)
      do until rs2.eof%>
       <OPTION VALUE=<%=rs2("id")%>><%=rs2("Filename")%>
      <%rs2.movenext
      Loop
      rs2.close
      set rs2=nothing
     end sub
    %>
     </SELECT> OR <input type=submit name=add value="Add Page"></td></tr>
    <%
     if request.form("filename2") <> "" and Request.Form("add") = "" and Request.Form("del") = "" then
      dim filename2
      dim fileid
      if request.form("filename2") = "0" then
       filename1 = request.form("filename3")
      else
       filename1 = request.form("filename2")
      end if
      if filename1 = "" then
       MySQL="select max(id) as id from webdb"
       set rs2=conn.execute(MySQL)
       id = rs2("id")
       rs2.close
       MySQL="select webdb.id, Filename,titlefield,messagefield,defaultpg from webdb where id="& id
      else
       MySQL="select webdb.id, Filename,titlefield,messagefield,defaultpg from webdb where id="& filename1
      end if
      set rs2=conn.execute(MySQL)
      filename2 = rs2("filename")
      fileid = rs2("id")
      titlefield = rs2("titlefield")
      messagefield = rs2("messagefield")
      if rs2("defaultpg") = "Y" then
       ckstat = "Checked"
      end if
    %>
    <td nowrap>Page Being Edited:</td><td>
      <input type=text name=edfile value=<%=filename2%> size="20"><input type=hidden name=filename4 value="<%=filename2%>"><input type=hidden name=filename3 value=<%=fileid%>>&nbsp;&nbsp;<input type=submit name=del value="Delete Page"></td></tr>
    <%
     else
    %>
    <td nowrap>New Page Name:</td><td>
      <input type=text name=newfile value="" size="20">&nbsp;&nbsp;<input type=submit name=del value="Delete Page"></td></tr>
    <%
     end if
    %>
    <tr valign="top"><td Width="70"class="SubHead">Title:</td><td width="*" valign="bottom">
    <input name="TitleField" type="text" maxlength="100" size="40" id="TitleField" value="<%= TitleField %>"class="NormalTextBox" style="width:600px;">
    </td></tr><tr valign="top"><td Width="100"class="SubHead" nowrap>Page Content:</td><td><input type=checkbox name=default value="Y" <%=ckstat%>> Set as The Default Page?</td></tr><tr><td width="*" colspan=2>
    <%         
     Dim editor
     Set editor = New CuteEditor
     editor.ID = "Editor1"
     editor.Text = MessageField
     editor.FilesPath = "CuteEditor_Files"
     editor.ImageGalleryPath = "/Uploads"
     editor.MaxImageSize = 50
     editor.AutoConfigure = "EnableAll"
     editor.Width = "100%"
     editor.Height = 350
     editor.Draw()
     Request.Form("Editor1_HTMLContent")
    %>
    </td></tr></table></div><br><br></td></tr></table></td></tr></table>
    </form>
    </body>
    <%
     sub addnew()
      TitleField = Request.Form("TitleField")
      MessageField = Request.Form("Editor1_HTMLContent")  
      fname = Request.Form("newfile") 
      if default = "Y" then
       sql = "update webdb set defaultpg = ''"
       conn.execute(sql)
      end if
     
      sql="select Filename, TitleField,MessageField,defaultpg from webdb"
      set rs=server.createobject("adodb.recordset")
      rs.open sql,conn,3,3
      rs.addnew
      rs("Filename") = fname
      rs("TitleField") = TitleField
      rs("MessageField") = MessageField
      rs("defaultpg") = Request.Form("default")
      rs.update
      response.write "<font size=5 color=darkred>Page Has Been Added!</font>"
      rs.close
      set rs = nothing
      
     end sub 
     
     sub updatefile()
      filename = request.form("edfile")
      title = Request.Form("TitleField")
      mess = Request.Form("Editor1_HTMLContent")
      default = Request.Form("default")
      filename4 = request.form("edfile")
      if default = "Y" then
       sql = "update webdb set defaultpg = ''"
       conn.execute(sql)
      end if
      sql = "update webdb set filename='" & filename4 &"' ,titlefield='" & title & "',messagefield='" & mess &"', defaultpg='"& default &"' where id =" & request.form("filename3")
      response.write "<font size=5 color=darkred>Page Has Been Updated!</font>"
      conn.execute(sql)
     end sub
     
     sub delrec()
      sql = "Delete * from webdb where id =" & request.form("filename3")
      response.write "<font size=5 color=darkred>Page Has Been Delete!</font>"
      conn.execute(sql)
     end sub
    %>
    </html>

     
    Jimmy brown
    Kingsport City schools
    technical services
View as RSS news feed in XML