Click here to Skip to main content
11,634,827 members (67,605 online)
Click here to Skip to main content

News System with ASP

, 5 Aug 2004 71.7K 1.5K 44
Rate this:
Please Sign up or sign in to vote.
Simple News System using ASP and MS Access

Sample Image - logo.png 

ASP News System

This is a simple news system that can be easily added to any website. Download full asp news source code and instructions.

This code uses the following technolgies

  • ASP (Active Server Pages).
  • MS Access Database.

Be sure that you your system or web host supports these technologies.

Details

Start by editing the settings.asp file, this file contains the basic settings for the news system such as:

  • Your News Title
  • Login Code (password)
  • Number of stories to show per page.
  • Database path
newstitle = "News Demo"
logincode = "1234"
show_stories = "10"
database_path = Server.MapPath("news_data.mdb")

This file also contains a few functions that are used as well as some style settings that can be changed to  customize the look of the news system

login

The login page is a simple html form which is checked against the login code that is set in the settings.asp file. If successful, then it sets the session and continues to the admin area.

<%Option Explicit%>
<!--<span class="code-comment"> #INCLUDE FILE="settings.asp" --></span>
<%
' Intercept all exceptions to display user-friendly error

if Request.Form("mynumber") = "" then
response.redirect("login-news.asp?l=password_blank")
End If

'set variables from form
FormPwd = Request.Form("mynumber")
FormPwd = replace(FormPwd,"'","''")

'run login or return to login page
if formpwd = logincode then
    Session("LoginID") = formpwd
else
response.redirect("login-news.asp?l=incorrect_login_or_password")
End if

'final redirect
response.redirect("news-admin.asp")
%>

Once logged in the screen looks very similar to the public news screen, but with more administrative options.

asp news

<!--<span class="code-comment"> #INCLUDE FILE="login-check.asp" --></span>

From here you can edit current news stories add new news stories, or delete news stories.

The edit news stories, will basically read the values from the database based on the querystring value passed, and put them into an html form which can then update the database with your changes made.

asp news

<%option explicit%>
<!--<span class="code-comment"> #INCLUDE FILE="login-check.asp" --></span>
<!--<span class="code-comment"> #INCLUDE FILE="settings.asp" --></span>
<%

id = request("id")
if id < 1 then
    response.write (errormsg)
    response.end
end if

Set dConn = Server.CreateObject("ADODB.Connection")
dConn.Open "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & database_path

'========================================
if request.form("ispostback") = 1 then
    set updateRS = Server.CreateObject("ADODB.RecordSet")
    updateSQL = "SELECT * from tblnews where ID = " & ID & ";"
    updateRS.Open updateSQL,dConn, 1,3
        urecordcount = updateRS.recordcount
        if urecordcount <> 1 then
            updateRS.Close
            Set updateRS = Nothing
            response.redirect("default.asp?norecord")
        end if
    updateRS("newsdate") = checkdate(request.form("newsdate"))
    updateRS("expire") = checkdate(request.form("expire"))
    updateRS("newstitle") = Presubmit2(request.form("newstitle"))
    updateRS("newsbody") = Presubmit2(request.form("newsbody"))
    updateRS("active") = request.form("active")
    updateRS.update
    updateRS.Close
    set updateRS = Nothing
    message = "<p><font color='#FF0000'>Update Successful</font></p>"
end if
'========================================

strSQL = "SELECT expire, id, newsdate, newstitle, 
  newsbody, active from tblnews where ID = " & ID & ";"
Set newsRS = Server.CreateObject("ADODB.recordset")
newsRS.Open strSQL, dConn, 1, 3

        recordcount = newsrs.recordcount
        if recordcount < 1 then
            newsRS.close
            set newsRS = nothing
            dConn.close
            set dConn = nothing
            response.write (errormsg)
            Response.end
        end if

For fnum = 0 To newsRS.Fields.Count-1
    execute(newsRS.Fields(fnum).Name & " = 
  newsRS(" & CHR(34) & newsRS.Fields(fnum).Name & CHR(34) & ")")
Next
if newsbody <> "" then
    newsbody = undo(newsbody)
end if

%>
<!--<span class="code-comment"> #INCLUDE FILE="admin-menu.asp" --></span>
<title>Edit News</title>
<h3><%=newstitle%></h3>

<%=message%>

<form action="edit-news.asp" method="post" name="frm" id="frm">
<table border=2 bordercolor="#CCCCFF" CELLSPACING=0 CELLPADDING=4>
<tr>
    <td>News Title</td>
    <td><input type="text" name="newstitle" 
  value="<%=newstitle%>" size="50" class="cssborder"></td>
</tr>
<tr>
    <td>News Date</td>
    <td><input type="text" name="newsdate" 
  value="<%=newsdate%>" size="12" class="cssborder"></td>
</tr>
<tr>
    <td>News Expire Date</td>
    <td><input type="text" name="expire"
   value="<%=expire%>" size="12" class="cssborder"></td>
</tr>
<tr>
    <td valign="top">News Text</td>
    <td><textarea cols="50" rows="8" 
  name="newsbody" class="cssborder"><%=newsbody%></textarea></td>
</tr>
<tr>
    <td valign="top">Active</td>
    <td>
    <% if active = "1" then%>
    <input type="checkbox" name="active" value="1" checked>
    <% else %>
    <input type="checkbox" name="active" value="1">
    <% end if %>
    </td>
</tr>

<tr>
    <td colspan="2">
    <input type="hidden" name="id" value="<%=id%>">
    <input type="hidden" name="ispostback" value="1">
    <input type="submit" value="update" class="cssborder"> 
    <input type="reset" class="cssborder">
    </td>
</tr>
</table>
</form>
<p><a href="edit-news.asp?id=<%=id%>">reload</a></p>

When adding news, the browser simple goes to the news-cmd.asp file, which acts like a utility file, doing multiple functions depending on what value is passed to it.

In this code, you can see where the insert takes place. To make this simple a standard SQL insert is used to populate the news database with a new record which can then be easily edited. You can also see from this file that if a delete command is sent to the file with a record id, then a news item can also be deleted from this page.

<!--<span class="code-comment"> #INCLUDE FILE="login-check.asp" --></span>

Conclusion

Download full asp news source code and instructions. That is about all there is to it, this is just a very simple news system an easy way to keep your site updated from a simple and quick web interface. Hope you enjoy it!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

aa2max
United States United States
Live in Michigan, USA

You may also be interested in...

Comments and Discussions

 
GeneralI can't edit news Pin
arezoot2-Dec-07 1:10
memberarezoot2-Dec-07 1:10 
QuestionCan not open Database Pin
anin2star25-Jun-07 15:57
memberanin2star25-Jun-07 15:57 
GeneralDatabase - Adding Fields Pin
The-SOLE26-Aug-04 2:48
memberThe-SOLE26-Aug-04 2:48 
GeneralRe: Database - Adding Fields Pin
aa2max26-Aug-04 3:53
memberaa2max26-Aug-04 3:53 
GeneralRe: Database - Adding Fields Pin
The-SOLE26-Aug-04 11:37
memberThe-SOLE26-Aug-04 11:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150728.1 | Last Updated 6 Aug 2004
Article Copyright 2004 by aa2max
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid