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'
<%
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. |
 |
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 %>
<%
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"
-->
<%
Dim Connection, sConnString
Dim headline, news, thedate, SQL
headline=request.form("headline")
news=request.form("news_story")
thedate=Date()
SQL = "INSERT INTO tblNews(headline,News_Story,Story_date)
Values " & _
"( '" & headline & "', '" & news
& "', '" & thedate & "')"
Set Connection = Server.CreateObject("ADODB.Connection")
sConnString="PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("../db/news.mdb")
Connection.Open(sConnString)
Connection.execute(SQL)
connection.Close
Set connection = Nothing
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.