 |
| Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

March 19th, 2004, 07:48 AM
|
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Customized error page for missing records
I have a site running asp pages and mysql database.
I wonder if this post should be done either in asp topics or mysql topics.
I delete time after time some records.
But the robots of the search engines (google etc) scan and archive pages that contain records that I have deleted.
So, if someone does a search in a search engine and the search engine returns as results one or many of my web pages that contain database records that I have previously deleted, then the user goes to a page of my web site that contain errors!
My question is how to make a redirection to a customized web page, in such case that someone requests a record that is not present at the momment(deleted from me).
This is not the case of iis redirection of pages that are 'not found'.
The page is dynamic asp, is always present (found) but is not the record someone requests.
Can you please give me the right asp code?
|
|

March 19th, 2004, 07:54 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
If you are retrieving the record from a database with ADO and a Recordset, you can check its EOF property and see of the record exists. If it doesn't, display a message. Something like this will do the trick
Code:
' Code for your recordset here
If MyRecordset.EOF Then
Response.Write("We're sorry, but the article you are looking
for can no longer be found on this address.
Why don't you try to <a href=""Search.asp"">search</a> for it,
or check out our <a href=""/"">home page</a>?")
Else
' Articles is found, so proceed as normal.
End If
This code displays the error message (with some useful links) when the record was not found in the database.
Does this help?
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

March 21st, 2004, 02:40 PM
|
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for your response.
My code is the following:
<%
Dim Recordset1__MMColParam
Recordset1__MMColParam = "1"
If (Request.QueryString("Id") <> "") Then
Recordset1__MMColParam = Request.QueryString("Id")
End If
%>
<%
Dim Recordset1
Dim Recordset1_numRows
Set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_dytika29_STRING
Recordset1.Source = "SELECT * FROM 29articles WHERE Id = " + Replace(Recordset1__MMColParam, "'", "''") + ""
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()
Recordset1_numRows = 0
%>
Where should I put the code you previously told me?
|
|

March 21st, 2004, 04:25 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Somewhere right after you use the Open() method.
Since you're not showing the code for displaying the data from the record, it's hard to tell the exact location, but if you consider the following generic example, you should be able to figure out where to put it in your page:
Code:
...
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()
If MyRecordset.EOF Then
Response.Write("We're sorry, but the article you are looking
for can no longer be found on this address.
Why don't you try to <a href=""Search.asp"">search</a> for it,
or check out our <a href=""/"">home page</a>?")
Else
' Articles is found, so proceed as normal.
End If
It looks like you're using Dreamweaver for your coding. If that is true, take a look at the Server Behaviors panel. It has a Show Region If Recordset Is Empty and Show Region If Recordset Is Not Empty.
Wrap your error message in the Is Empty, and wrap your normal record display in a Is Not Empty behavior.
Cheers,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

March 22nd, 2004, 11:50 AM
|
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for your response.
You guess well, I use dreamweaver mx 2004.
I applied the show region if recordset is not empty.
I want to tell you how i did it, because something was wrong.
My site consists of a master detail page set.
I supposed and then I tried to apply this server behavior in the detail page.Am I wrong?
So I selected (visually-then the dreamwaver selects the appropriate code automatically) dynamic field1 in my page(detail page), then I applied the 'Show region if recordset is not empty'. My detail pages has also another one dynamic field2, so I 've done this once again.
Then, I saved.
Then I go to Internet explorer.
I wrote http://localhost/detailpage.asp?id=(great number that is not exist in the database). And then it displays the usual error that it displayed all the time:
Error Type:
ADODB.Field (0x800A0BCD)
Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.
What I 've done wrong?
Please help me, I am not a programmer, just an intermeddiate user.
I think we are close to the solution.
Thanks in advance.
|
|

March 22nd, 2004, 12:48 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
Yes, you have done the correct thing. If the record is deleted, it won't show up in the master page anyway, so the Detail page is the right page to apply the Show Region If Recordset Is Not Empty behavior. (Although you may need to add one to the Master page as well, in case ALL records are deleted, and there is nothing to show on the Master page).
Can you post the code for your page? It looks like you missed a dynamic field here and there.
What I usually do is wrap most of the <body> tag in one Show Region If Recordset Is Not Empty behavior. This way, I can be sure all content is hidden when the record is not found. Then, if necessary, I wrap the <title> tag in such a behavior as well. Finally, I use a Show Region If Recordset Is Empty behavior to display an error message.
Using individual behaviors for each dynamic field can quickly mess up your page.
Cheers,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

March 22nd, 2004, 02:56 PM
|
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for your response
Here is the whole code of detail page:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1253"%>
<%
Dim Recordset1__MMColParam
Recordset1__MMColParam = "1"
If (Request.QueryString("Id") <> "") Then
Recordset1__MMColParam = Request.QueryString("Id")
End If
%>
<%
Dim Recordset1
Dim Recordset1_numRows
Set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_dytika29_STRING
Recordset1.Source = "SELECT * FROM 29articles WHERE Id = " + Replace(Recordset1__MMColParam, "'", "''") + ""
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()
Recordset1_numRows = 0
%>
<html>
<head>
<title>29 ÃÃÃÃÃÃ - ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1253">
<meta name="" content="ÃéôùëïáêáñÃáÃÃá, Ãåóïëüããé, ÃãñÃÃéï, Ãáýðáêôïò, ÃüÃéôóá, Ãìöéëï÷Ãá. à ÃéôùëïáêáñÃáÃéêà Ãéêôõáêà Ãýëç Ã
ÃçìÃñùóçò, åéäÃóåéò, ôïðéêà ÃÃá, ðëçñïöüñçóç. ÃëåêôñïÃéêà åöçìåñÃäá. ÃëåêôñïÃéêà Ãýëç. Internet . Portal. ">
<meta name="keywords" content="ÃéôùëïáêáñÃáÃÃá, Ãåóïëüããé, ÃãñÃÃéï, Ãáýðáêôïò, ÃüÃéôóá, Ãìöéëï÷Ãá, Ã÷åëþïò, Ã
ýçÃïò, ëéìÃïèÃëáóóá, Ãñé÷ùÃÃäá, ÃÃñìï, ÃáõðáêôÃá, Ãéôùëéêü, Portal, Ã
ÃçìÃñùóç, åéäÃóåéò, ÃÃá, ðëçñïöüñçóç" />
</head>
<style>
<!--
a{
text-decoration:none;
line-height: 1px;
font-family: Arial, Helvetica, sans-serif;
font-size: 9px;
}
//-->
</style>
<SCRIPT LANGUAGE="JavaScript">
<!--PRINT
<!-- Begin
function printWindow() {
bV = parseInt(navigator.appVersion);
if (bV >= 4) window.print();
}
// End -->
</script>
<body text="#000000" link="#000000" vlink="#000000" alink="#000000" leftmargin="0" topmargin="0">
<style>
<!--
a{text-decoration:none}
//-->
</style>
<script language="JavaScript" type="text/JavaScript">
<!--
function click(e){if (document.all) if (event.button == 2) return false;if
(document.layers) if (e.which == 3) return false;}
function click2(){event.returnValue=false;return false;}if (document.layers)
document.captureEvents(Event.MOUSEDOWN);document.o nmousedown=click;document.oncontextmenu=click2;
// --> </script>
<script language="JavaScript1.2">
//Disable
function disableselect(e){
return
}
function reEnable(){
return
}
//if IE4+
document.onselectstart=new Function ("return false")
//if NS6
if (window.sidebar){
document.onmousedown=disableselect
document.onclick=reEnable
}
</script>
<table border="0" align="left" cellspacing="0">
<tr bordercolor="#111111" bgcolor="#FFFFFF">
<td height="104" valign="top" bgcolor="#fcfcfc"><img src="main/nav/graphic/logo.jpg" width="130" height="120">
<td width="523" height="104" rowspan="1" bgcolor="#fcfcfc" class="text8pt"><p align="center"><img border="0" src="main/nav/graphic/lor1.jpg" width="520" height="10"><img border="0" src="main/nav/graphic/Upframe.jpg" width="520" height="50"><span style="letter-spacing: 1"></span><img border="0" src="main/nav/graphic/lor2.jpg" width="521" height="10">
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://active.macromedia.com/flash4/cabs/swflash.cab#version=4,0,0,0" width="520" height="16">
<param name="quality" value="High">
<param name="bgcolor" value="FFFFFF">
<param name="_cx" value="17145">
<param name="_cy" value="476">
<param name="FlashVars" value="-1">
<param name="Src" value="main/nav/graphic/Rotating.swf">
<param name="WMode" value="Window">
<param name="Play" value="-1">
<param name="Loop" value="0">
<param name="SAlign" value>
<param name="Menu" value="-1">
<param name="Base" value>
<param name="Scale" value="ShowAll">
<param name="DeviceFont" value="0">
<param name="EmbedMovie" value="0">
<param name="SWRemote" value>
<embed src="main/nav/graphic/Rotating.swf"
width="520" height="16" quality="high" bgcolor="#FFFFFF"
type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"> </embed>
</object>
</p></td>
<td width="138" rowspan="1" bgcolor="#fcfcfc" class="text8pt"><img src="main/nav/graphic/logo-deji5.jpg" width="130" height="120"></td>
</tr>
<tr>
<td width="130" rowspan="4" valign="top" bgcolor="#f2f2ff"><div align="center">
<div align="right">
<p> </p>
<p align="center"><span class="cat"><a href="index.asp">ÃÃÃÃÃÃ ÃÃ
ÃÃÃÃ </a></span></p>
<table width=125 height="70" cellpadding=0 cellspacing=0 bgcolor=white>
<tr>
<td width="121" height="40" valign="top" bgcolor="#EEEEEE"><p style=" margin-left:3px; margin-bottom: -20" class="cat">
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="115" height="70">
<param name="movie" value="main/nav/graphic/29banner2.swf">
<param name="quality" value="high">
<embed src="main/nav/graphic/29banner2.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="115" height="70"></embed>
</object>
</p></td>
</tr>
</table>
<table width=125 height="70" cellpadding=0 cellspacing=0 bgcolor=white>
<tr>
<td width="121" height="40" valign="top" bgcolor="#EEEEEE"><p style=" margin-left:3px; margin-bottom: -20" class="cat">
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="115" height="70">
<param name="movie" value="main/nav/graphic/Tzianos.swf">
<param name="quality" value="high">
<embed src="main/nav/graphic/Tzianos.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="115" height="70"></embed>
</object>
</p></td>
</tr>
</table>
<p> </p>
<p> </p>
</div>
<div align="right">
<p align="center" class="cat" style=" margin-left:3px; margin-bottom: -20"></p>
<p align="center" class="cat" style=" margin-left:3px; margin-bottom: -20"> </p>
</div>
<p></p>
<p> </p>
</div></td>
<td height="34" align="default"><div align="center"><strong><%=(Recordset1.Fields.Item( "Subjectw").Value)%></strong></div></td>
<td width="138" rowspan="4" align="right" valign="top" bgcolor="#f2f2ff"> <p> </p>
<table width=130 height="80" cellpadding=0 cellspacing=0 bgcolor=white>
<tr>
<td width="121" height="40" valign="top" bgcolor="#EEEEEE"><p align="right" class="cat" style=" margin-left:3px; margin-bottom: -20"><a href="main/nav/docs/symmetoxh.htm"><img src="main/nav/graphic/symmetoxh.jpg" width="115" height="70" border="0"></a>
</p>
</td>
</tr>
</table>
<table width=130 height="80" cellpadding=0 cellspacing=0 bgcolor=white>
<tr>
<td width="121" height="40" valign="top" bgcolor="#EEEEEE"><p style=" margin-left:3px; margin-bottom: -20" class="cat">
</p> </td>
</tr>
</table>
<table width=130 height="80" cellpadding=0 cellspacing=0 bgcolor=white>
<tr>
<td width="121" height="40" valign="top" bgcolor="#EEEEEE"><p align="center" class="cat" style=" margin-left:3px; margin-bottom: -20"> </p></td>
</tr>
</table> </td>
</tr>
<tr>
<td height="34" align="default"><div align="center"><img src="<%=(Recordset1.Fields.Item("29Image").Value)% >"></div></td>
</tr>
<tr>
<td width="523" align="default" style="line-height: 150%"><div align="justify">
<p align="justify" class="unnamed1"><%=(Recordset1.Fields.Item("29Con tent").Value)%> </p>
<p align="center" class="unnamed1"> </p>
</div></td>
</tr>
<tr>
<td height="23" align="default"> </td>
</tr>
<tr>
<td height="14" colspan="3" valign="top" bgcolor="#f2f2ff"><table width="795" border="0" align="right" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td align="middle" width="130" bgcolor="#eeeeee"> </td>
<td align="middle" width="190" bgcolor="#eeeeee"> </td>
<td align="middle" width="78" bgcolor="#eeeeee"> </td>
<td align="middle" width="46" bgcolor="#eeeeee">
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>
</td>
<td align="middle" width="213" bgcolor="#eeeeee"><!IMG HEIGHT=20 WIDTH=80 SRC="/global/advs/80x20/" BORDER=0></td>
<td align="middle" width="138" bgcolor="#eeeeee"><!IMG HEIGHT=20 WIDTH=80 SRC="/global/advs/80x20/" BORDER=0></td>
</tr>
<tr bgcolor="#333366">
<td height="10" colspan="6">
<p align="center"
style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; MARGIN-LEFT: 10px; COLOR: white; FONT-FAMILY: Tahoma">Copyright © 2002-2003-2004 - </p></td>
</tr>
</tbody>
</table></td>
</tr>
</table>
<p> </p>
<p> </p>
</body>
</html>
Thanks in advance
|
|

March 22nd, 2004, 03:12 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
I may be missing something here, but I don't see the Show Region behaviors here, right? Is this an old version of the page?
If I were you, I'd select the entire <table> element in the body of your page. With the table selected, apply the behavior that hides the table when the recordset is empty.
Then add the error message at the end of the page, and apply the other server behavior.
Cheers,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

March 22nd, 2004, 04:03 PM
|
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for your response.
The code I posted was the original one.
I selected the table and then applied the 'show region if recordset is not empty', as you told me.
Now the results of my tests are better. When I hit the example I wrote in the previous post (page that contains deleted record), no page(blank) is displayed.
But I have not understood and I 've not used the other server behavior, 'show region if recordset is empty'.
What do I have to define with this one?
Something like a redirection? Or what else?
Is it useful to use it? What do you suggest, what to select and apply?
Thanks in advance
|
|

March 22nd, 2004, 04:22 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
It depends on what you want. You can indeed redirect to another page, or to a page that really doesn't exist, so Google sees your page as a 404. However, that's tricky, as it may decide to stop visiting the other legal pages too (after all, you're talking about the same physical page).
What I would do, and suggested before, is to add some sort of error message, at the bottom (or any other location) of the page. Something like this:
<body>
<ServerBehavior type="Show Region If Recordset Is Not Empty">
<table>
... This table is shown when the recordset is empty
</table>
</ServerBehavior>
<ServerBehavior type="Show Region If Recordset Is Empty">
Hi there, and welcome to my site.
The article you're trying to request does no longer exist? Why don't you try our search page or our home page instead?
</ServerBehavior>
</body>
The xml <ServerBehavior> tags are just for fun, and to show you the idea. In reality, you'll need to apply the appropriate Server Behaviors to the region they contain.
May I recommend the book Beginning Dreamweaver MX 2004? It deals with this topic and much more in great detail.
Cheers,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|
 |