Forums
This topic is locked
Problem with update function
Posted 31 Oct 2004 16:36:37
1
has voted
31 Oct 2004 16:36:37 Zain Magsi posted:
Hi,I have a asp page that updates a record in an access database. The page uses a asp class and draws a wysiwyg editor to achieve that task. It works by reading and displaying the text from the db table, but it writes another copy of the record instead of updating it when the user clicks on the save button. How can I have it update the db instead of makin another entry in the table. The code for the page is pasted below:
<!-- #include file = "include_CuteEditor.asp" -->
<%
'=========================================================
' Retrieve the data from editor:
' If you specify your editor ID is "Editor1"
' Retrieve the data from editor: Request.Form("Editor1_HTMLContent"

'=========================================================
%>
<html>
<head>
<title>Page Title</title>
<link href="example.css" type="text/css" rel="stylesheet">
</head>
<body>
<form name="theForm" action="todatabase2.asp?action=save" method="post" ID="Form1">
<TABLE cellSpacing=0 cellPadding=0 width="100%" align=center border=0 ID="Table1">
<TR>
<TD class=ContentBg vAlign=top height=480><BR>
<TABLE cellSpacing=0 cellPadding=4 width="100%" align=center border=0 ID="Table2">
<TR>
<TD id=LeftPane width=180 valign=top>
</TD>
<TD id=ContentPane width=* vAlign=top bgcolor=white>
<div style="margin:10px;">
<%
dim conn
dim connstr
Set conn = Server.CreateObject("ADODB.Connection"

connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("../../db/rusty.mdb"

conn.Open connstr
dim content
if request("action"

Catering1 = Request.Form("Editor1_HTMLContent"

sql="select Catering1 from Catering"
set rs=server.createobject("adodb.recordset"

rs.open sql,conn,3,3
rs.addnew
rs("Catering1"

rs.update
response.write "<font size=5 color=darkred>Message added</font>"
response.write "<br>"
rs.close
set rs = nothing
else
MySQL="select top 1 * from Catering order by id DESC"
set rs2=conn.execute(MySQL)
if not rs2.eof then
Catering1 = rs2("Catering1"

rs2.close
set rs2=nothing
end if
end if
%>
<table width="100%" cellspacing="1" cellpadding="5" border="0">
<tr valign="top">
</tr>
<tr valign="top">
<td width="*">
Message:
<br>
<%
Dim editor
Set editor = New CuteEditor
editor.ID = "Editor1"
editor.Text = Catering1
editor.FilesPath = "CuteEditor_Files"
editor.ImageGalleryPath = "/Uploads"
editor.MaxImageSize = 50
editor.AutoConfigure = "EnableAll"
'editor.Template= "Bold,Italic,Underline"
'editor.StyleSheetPath = "/grey2.css"
'editor.Width = 740
'editor.Height = 300
editor.Draw()
' Request.Form("Editor1_HTMLContent"

%>
</td>
</tr>
</table>
</div>
<br>
<br>
<%= TitleField %>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
Please Help,
Zain
Replies
Replied 01 Nov 2004 11:36:49
01 Nov 2004 11:36:49 Lee Diggins replied:
Hi Zain
probably because you have both rs.addnew and rs.update, comment out the addnew method and see what happens.
Digga
Sharing Knowledge Saves Valuable Time!!!
probably because you have both rs.addnew and rs.update, comment out the addnew method and see what happens.
Digga
Sharing Knowledge Saves Valuable Time!!!