The page is an online database editor.
The code on my home PC works perfectly, No problems at all. However I have
tried to run the page on the intranet server at work, All seems to be OK.
Except for when you add/update/delete to/from the database. The page
doesn't refresh with the new information on the database. It just stays the
same, unless you refresh the page manually or close the browser and go to
the page again or if you re-order the list. So I know the database is being
updated correctly. If you manually refresh the page after adding a new url,
you actually get 2 of the same url's in the database as you have to resend
the information to the page when you do a refresh.
I have tried playing with the code to try to figure out why this is
happening or any way round it, but I'm getting no-where. Can you please
take a look and see if there is anything you can think of to get around
this?
The code is below:
The code on my home PC works perfectly, No problems at all. However I have
tried to run the page on the intranet server at work, All seems to be OK.
Except for when you add/update/delete to/from the database. The page
doesn't refresh with the new information on the database. It just stays the
same, unless you refresh the page manually or close the browser and go to
the page again or if you re-order the list. So I know the database is being
updated correctly. If you manually refresh the page after adding a new url,
you actually get 2 of the same url's in the database as you have to resend
the information to the page when you do a refresh.
I have tried playing with the code to try to figure out why this is
happening or any way round it, but I'm getting no-where. Can you please
take a look and see if there is anything you can think of to get around
this?
The code is below:
Code:
<%
Option Explicit
Dim page_name
page_name = "editurls.asp"
'********************************* Defining a couple variables ****************
Dim strConnect
strConnect = "urlcheck"
Dim next_action
If Request.Form("next_action") <> "" Then
next_action = Request.Form("next_action")
Else
next_action = "show list"
End If
'********************************* Show List **********************************
Function show_list
Dim objCommand
Dim sqlGetList
Dim rsGetList
Dim order_by ' addition to code 1 line
If Request.Form("reorder") <> "" Then ' addition to code 5 lines
order_by = request.Form("reorder")
Else
order_by = "websitename"
End If
sqlGetList = "SELECT * FROM urllist ORDER BY "&order_by 'line changed for order_by variable
on Error Resume Next
Set objCommand = Server.CreateObject("ADODB.Command")
objCommand.ActiveConnection = strConnect
objCommand.CommandText=sqlGetList
objCommand.CommandType=adCmdText
Set rsGetList = objCommand.Execute
Set objCommand = Nothing
rsGetList.MoveFirst
'---- Do the display now
%>
<form method=POST action="<%=page_name%>" name="frmUrlList">
<input type="hidden" name="next_action" value="show list">
<input type="hidden" name="record_number">
<input type="hidden" name="reorder" value="websitename"> <% 'additional element for reorder %>
<table class="urlListTable">
<tr>
<th><a class="headers">Options</a>
</th>
<th>
<a href="#" onClick="frmUrlList.reorder.value='websitename'; textSubmit('frmUrlList');" class="headers">Website</a>
</th>
<th><a href="#" onClick="frmUrlList.reorder.value='url'; textSubmit('frmUrlList');" class="headers">Address</a>
</th>
<th>
</th>
</tr>
<%
Dim rowCounter
Do While NOT rsGetList.EOF
%>
<tr class="listRow<%=(rowCounter mod 2)%>">
<td align="center"> <% ' code changes follow, use javascript textSubmitCheck for delete to confirm %>
<input type="button" value="Update" onClick="frmUrlList.record_number.value='<%=rsGetList("urlPK")%>'; frmUrlList.next_action.value='update record'; textSubmit('frmUrlList');" class="half_button">
<input type="button" value="Delete" onClick="frmUrlList.record_number.value='<%=rsGetList("urlPK")%>'; frmUrlList.next_action.value='delete record'; textSubmitCheck('frmUrlList');" class="half_button">
</td>
<td>
<a href="<%=rsGetList("url")%>" class="my_a"><%=rsGetList("websitename")%></a>
</td>
<td>
<%=rsGetList("url")%>
</td>
</tr>
<%
rowCounter = rowCounter + 1
rsGetList.MoveNext
Loop
%>
<tr class="listRow<%=(rowCounter mod 2)%>">
<td align="center"> <% ' code changes follow, use javascript textSubmitCheck for add to confirm %>
<input type="button" value="Add New Website" onClick="frmUrlList.next_action.value='insert record'; textSubmitCheck('frmUrlList');" class="full_button" >
</td>
<td>
<input type="text" name="txtNewWebSite" class="txtInput" value="Add A New Web Site!" size="20">
</td>
<td>
<input type="text" name="txtNewUrl" class="txtInput" value="Put the Address Here! With Or Without The [URL unfurl="true"]http://"[/URL] size="20">
</td>
</tr>
</table>
</form>
<%
End Function
'********************************* Update Page **********************************
Function update_page
Dim objCommand
Dim sqlGetRecord
Dim rsGetRecord
sqlGetRecord = "SELECT * FROM urllist WHERE urlPK = "&Request.Form("record_number")
on Error Resume Next
Set objCommand = Server.CreateObject("ADODB.Command")
objCommand.ActiveConnection = strConnect
objCommand.CommandText=sqlGetRecord
objCommand.CommandType=adCmdText
Set rsGetRecord = objCommand.Execute
Set objCommand = Nothing
%>
<form method=POST action="<%=page_name%>" name="frmUpdateForm" onSubmit="return confirm('Are you sure?');">
<input type="hidden" name="next_action" value="update submit">
<input type="hidden" name="record_number" value="<%=Request.Form("record_number")%>">
<table class="urlListTable">
<tr class="listRow0">
<th>
Website
</th>
<th>
Address
</th>
<th>
Option
</th>
</tr>
<tr>
<td>
<input type="text" name="txtWebSite" value="<%=rsGetRecord("websitename")%>" class="txtInput" size="20">
</td>
<td>
<input type="text" name="txtUrl" value="<%=rsGetRecord("url")%>" class="txtInput" size="20">
</td>
<td>
<input type="submit" value="Update!">
</td>
</tr>
</table>
</form>
<%
End Function
'********************************* Update Submit ********************************
Function update_submit
Dim objCommand
Dim sqlUpdateRecord
sqlUpdateRecord = "UPDATE urllist SET url='"&Request.Form("txtUrl")&"', websitename='"&Request.Form("txtWebSite")&"' WHERE urlPK = "&Request.Form("record_number")
on Error Resume Next
Set objCommand = Server.CreateObject("ADODB.Command")
objCommand.ActiveConnection = strConnect
objCommand.CommandText=sqlUpdateRecord
objCommand.CommandType=adCmdText
objCommand.Execute
Set objCommand = Nothing
End Function
'********************************* Insert Record ********************************
Function insert_record
Dim objCommand
Dim sqlInsertRecord
sqlInsertRecord = "INSERT INTO urllist(url,websitename) values('"&Request.Form("txtNewUrl")&"', '"&Request.Form("txtNewWebSite")&"')"
on Error Resume Next
Set objCommand = Server.CreateObject("ADODB.Command")
objCommand.ActiveConnection = strConnect
objCommand.CommandText=sqlInsertRecord
objCommand.CommandType=adCmdText
objCommand.Execute
Set objCommand = Nothing
End Function
'********************************* Delete Record ********************************
Function delete_record
Dim objCommand
Dim sqlDeleteRecord
sqlDeleteRecord = "DELETE FROM urllist WHERE urlPK = "&Request.Form("record_number")
on Error Resume Next
Set objCommand = Server.CreateObject("ADODB.Command")
objCommand.ActiveConnection = strConnect
objCommand.CommandText=sqlDeleteRecord
objCommand.CommandType=adCmdText
objCommand.Execute
Set objCommand = Nothing
End Function
'********************************* The Real Thing *****************************
%>
<html>
<head>
<title>Url List</title>
<script language="JavaScript">
<!--
function textSubmit(form_obj_name){
window.setTimeout(form_obj_name+'.submit()',1);
}
//Inside your script tags
function textSubmitCheck(form_obj_name){
if(confirm("Are you sure?")){ //if the click ok
window.setTimeout(form_obj_name+'.submit()',1); //do the submit
}
else{ //if they hit cancel
//I use eval here because I received the form_obj_name as a string
// rather than the object itself, eval takes a string and evaluates
// it as if it were a line of code.
eval(form_obj_name+".next_action.value='show list';"); //reset the next_action
}
}
//-->
</script>
<style> <% 'Styles!!! wheee. Should be self-explanatory, made a couple changes since first copy. %>
.urlListTable{
/*background:#00CCFF;*/
border:1px solid #000000;
padding:5px;
width:100%;
margin-top:30px;
}
.urlListTable th{
/*background:#66AADD; replaced by .headers class
border-right:1px solid #666666;
border-bottom:1px solid #666666;*/
height:20px;
width:100%;
}
.headers{
background: #88CCFF;
border-top:0px;
border-left:0px;
border-right:1px solid #666666;
border-bottom:1px solid #666666;
height:20px;
width:100%;
color:#000000;
text-decoration:none;
padding-bottom:3px; /* don't want it to make the size of the table cell change
object height = height + top border + bottom border + padding= 24 */
}
.headers:hover{
background-color: #ff0011;
border-top:1px solid #5599CC;
border-left:1px solid #5599CC;
border-right:2px solid #555555;
border-bottom:2px solid #555555;
padding-bottom:1px; /* don't want it to make the size of the table cell change
object height = height + top border + bottom border + padding= 24 */
}
.listRow0{
background-color:#cceeFF;
}
.listRow1{
background-color:#DDffbb;
}
.listHead{
font-size:32px;
font-family: cursive;
text-decoration: underline;
background:#66AADD;
border-right:1px solid #666666;
border-bottom:1px solid #666666;
height:50px;
text-align:center;
}
.half_button{
font-style:tahoma;
font-size:10px;
width:70px;
}
.full_button{
font-style:tahoma;
font-size:9px;
width:145px;
}
.txtinput{
width:100%;
}
.pageLayout{
width:95%;
text-align:center;
background:#eeeeee;
height:100%;
margin:0px;
}
.my_a{
color:#114411;
padding-left:5px;
padding-right:5px;
}
.my_a:hover{
color:#ffffff;
background-color:#ff0011;
}
</style>
</head>
<body>
<center>
<div class="pageLayout">
<table class="urlListTable">
<tr>
<td class="listHead">
The Url List
</td>
</tr>
</table>
<%
Select Case next_action
Case "show list"
show_list
Case "insert record"
insert_record
show_list
Case "update record"
update_page
Case "update submit"
update_submit
show_list
Case "delete record"
delete_record
show_list
Case Else
%>
<h1>Internal Error</h1>
Please contact site administrator.<br>
Error: Unknown Action Request<br>
<a href="<%=page_name%>">Click here to return to the list</a>
<%
End Select
%>
</div>
</center>
</html>