Codefixer - ASP tutorials, resources and software
asp.netPRO “ASP.NET Hosting with US & UK Data Centers!
Home   Articles   Resources   ASP directory   ASP Tutorials   Code Snippets   ASP Applications   Forum
Tuesday 6 January
MembersPro PayPal - ASP Membership software

USA & Europe Data Centers – DiscountASP.NET

Creating a News management system (Part 5)

We now want to add news. The way we will do that is by creating a web form which will allow us to enter news details. These details will posted to a second page 'insert_news.asp' and inserted into the database. Have a look at the code below.

'Add_news.asp'

<%
'Our login protection code
If Session("BlnLoggedIn") <> True Then
Response.Redirect("login.asp")
End If
%>
<html>
<head>
<title>News Management System - Add News</title>
</head>
<body>
<!--#include file="admin_navigation.asp" -->
<div align='center'>
<form name="form" method="post" action="insert_news.asp">
<br>
<table width="334">
<tr>
<td width="199"> headline: <br>
</td>
<td width="123">
<input type="text" name="headline" maxlength="50">
</td>
</tr>
<tr>
<td> news story: </td>
<td>
<textarea name="news_story" cols="35" rows="7"></textarea>
</td>
</tr>
<tr>
<td height="32" colspan="2">
<div align="center">
<input type="submit" name="Submit" value="Submit">
<input type="reset" name="reset" value="reset">
</div>
</td>
</tr>
</table>
</form>
</div>
</body>
</html>

This is how our page 'add_news.asp' will look.
ASP news management system

Save 'add_news.asp' in the 'admin' folder. Next we need a page that will process the news submitted. This will be the action page called 'insert_news.asp'. Here is what the code looks like for our page 'insert_news.asp'.

<%@ Language="VBScript" %>
<% Option Explicit %>
<%
'Our login protection code
If Session("BlnLoggedIn") <> True Then
Response.Redirect("login.asp")
End If
%>
<html>
<head><title>News Management System - News Added</title>
</head>
<body>
<!--#include file="admin_navigation.asp" -->
<%
'declare your variables
Dim Connection, sConnString
Dim headline, news, thedate, SQL

'receive values sent by form
headline=request.form("headline")
news=request.form("news_story")
' the date will be generated by the Date function rather than sent by the form
thedate=Date()
'declare SQL statement that will query the database
SQL = "INSERT INTO tblNews(headline,News_Story,Story_date) Values " & _
"( '" & headline & "', '" & news & "', '" & thedate & "')"

'Create ADO connection and recordset object
Set Connection = Server.CreateObject("ADODB.Connection")

'define the connection string, specify database
'driver and the location of database
sConnString="PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("../db/news.mdb")

'Open the connection to the database
Connection.Open(sConnString)

'execute the SQL statement
Connection.execute(SQL)

'lets close the connection object
connection.Close
Set connection = Nothing

'Let us know the news story has been submitted

response.write "<br><div align='center'>Your news has been entered</div>"
%>
</body>
</html>

Again save 'insert_news.asp' in the 'admin' folder. Notice in the code above we don't use the recordset object as we are not returning any records.

Our next page will allow us to delete news.




MembersPro PayPal - ASP Membership software

Membership Software Integrates with PayPal

  • Plug and play Membership script.
  • Recurring subscriptions or one time payment.
  • Up to 3 levels of membership subscription.
  • Easy set up and admin with free installation.
  • Works with PayPal.
  • Receive updates and add-ons for 2 years.
  • 1st class support and customization available.
  • Can be customized to support more levels.
  • Saves you hours and hours of development time and money.
  • PURCHASE YOUR COPY TODAY




3 MONTHS FREE – ASP.NET Hosting w/ US & UK Data Centers – Click Here!





About | Contact | Advertise | Feedback | Hire Us | Link

Site developed by Michael Wall - Web Design Belfast N.Ireland.
Copyright © 2000-2008. All rights reserved.

Do you intend to move to ASP.NET or have you already?
Yes will do
Have done
ASP does fine
Not a priority


Directory Software