PDA

View Full Version : Asp updating a field with text area


lewisdow
02-17-2005, 02:38 AM
Hi guys and gals,
I have a bit of a problem, I'm trying to display the contents of large fields within a text area, so that it can be edited and then posted back to be updated. The thing is the page works so long as you delet everything in the text area first, the field displays itself but if edits are made what seems to be hiden data drom the field prevents the new changes from being made. Esentially it works well but there are problems with the data as it goes in. Hopefully this makes sense, its a little hard to explain without screenshots of the blank spaces after the data.
Here is code.
Any help is much apprieciated.
First script is displaying data and the second is making the changes.
******************************************************
<%@LANGUAGE="VBSCRIPT"%>
<!-- #include file="DatabaseConnect2.asp" -->
<!-- #include virtual="/adovbs.inc" -->
<html>
<head>
<title>Untitled Document</title>
</head>

<body background="Upload/Pictures/MainBg.gif">
<%
dim objRs, strContent, strContent2
strContent = Request.Form("Update_Content")
strContent2 = Request.Form("Update_Content2")
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open "Chapters", DataConn , , , adCmdTable

'strSQL = "SELECT * FROM Chapters WHERE Chapters.SubjectID='" & request.querystring("Subjects") & "'"
'set objRS = dataconn.execute(strSQL)

If objRS.EOF then
response.Write("Sorry, there does not seem to be an existing chapter, new chaptersIDs must be inputted directly.")
else

%>
<form name="Update_Details" method="post" action="Update_Database.asp" >
<TextArea Name = "Update_Content" Rows = "13" Cols = "80" >
<%
Response.Write objRS("Content1")
%>
</textarea>

<p>
<TextArea Name = "Update_Content2" Rows = "13" Cols = "80" >
<%
Response.Write objRS("Content2")
%>
</textarea>

<p>
<input type="reset"> <input type="submit" Value="Submit" onClick="update_database.asp">

</form>
</body>
</html>
<%
objRS.close
set objrs = nothing
dataConn.close
set objconn = nothing
end if
%>

************************************************
<%@LANGUAGE="VBSCRIPT"%>
<!-- #include file="DatabaseConnect2.asp" -->
<!-- #include virtual="/adovbs.inc" -->
<html>
<head>
<title>Untitled Document</title>
</head>
<body background="Upload/Pictures/MainBg.gif">

<%
dim objRs, strContent
strContent = Request.Form("Update_Content")
strContent2 = Request.Form("Update_Content2")
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open "Chapters", DataConn , , adLockOptimistic, adCmdTable


ObjRS("Content1") = Request.Form("Update_Content")
ObjRS("Content2") = Request.Form("Update_Content2")
ObjRS.Update
objRS.close
Set objRS = Nothing
dataConn.close
Set dataConn = Nothing
%>
Changes Made !
</body>
</html>

jaywhy13
02-18-2005, 04:04 AM
Please surround your code with the code tag....
For the mean time... Try this debuggin technique....

comment out all the connection objects in the second script and just print out the results of the request.form to see if whatever is changed or adjusted on the form is transfered properly... try that first.
Print out to the screen strContent....
(for consistency... u forgot to dim strContent2)

That will help you to isolate immediately if summin is wrong with the transmission or if summin's wrong with the recordset method....

Also your Submit button has an onClick event in there.... why? Take that out.... The submit buton doesn't need help... Its already programmed to submit the form. And the url is already specified in the action of the form tag.

Finally how did u know that it didn't work? Have you already tried printing out the data to the screen or do you know from examining the database table after? That should help as well

miranda
02-18-2005, 10:35 AM
ok a few questions. What database are you working with? What are the datatypes of the columns inside the database? If this is an Access Database and they are of the datatype TEXT then you know the limitations as to the number of characters that can be input (max 255). each carraige return/line feed counts as a character, so does each space. Try using the Trim function on your update page to remove any leading and trailing spaces as well as carriage return/line feed.

To see if this is what is causing the problem get the length of the strings and output that to the browser.

Next if you must use the recordset object, dump the adovbs.inc file and replace it with this, the metadata type file library. It is faster and less load on the server.
<!-- METADATA TYPE="typelib" FILE="C:\Program Files\Common Files\System\ado\msado15.dll" -->

Next why did you declare 2 variables and then not use them later on in the page?

As I mentioned above not using a recordset object is less load on the server and it is also faster to just do it with a sql update statement.

Here is some changes with a test of the string lengths.

<%@LANGUAGE="VBSCRIPT"%>
<%Option Explicit 'Forces declaration of variables before using them%>
<!-- #include file="DatabaseConnect2.asp" -->
<!-- METADATA TYPE="typelib" FILE="C:\Program Files\Common Files\System\ado\msado15.dll" -->
<html>
<head>
<title>Untitled Document</title>
</head>
<body background="Upload/Pictures/MainBg.gif">

<%
dim objRS, strContent, strContent2
strContent = Request.Form("Update_Content")
strContent2 = Request.Form("Update_Content2")

Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open "Chapters", DataConn , , adLockOptimistic, adCmdTable

ObjRS("Content1") = Trim(strContent)
ObjRS("Content2") = Trim(strContent2)
ObjRS.Update
If Err.Count = 0 Then
Response.Write("Changes Made !")
Else
Response.Write "The length of strContent = " & Len(strContent)
Response.Write "<br />"
Response.Write "The length of strContent2 = " & Len(strContent2)
End If
objRS.close
set objrs = nothing
dataConn.close
Set dataConn = Nothing
%>
</body>
</html>