Author |
Topic  |
|
Astralis
Senior Member
   
USA
1218 Posts |
Posted - 12 December 2004 : 17:59:31
|
I don't know why some characters are being written in the database as invalid characters, such as the printer's apostrophe, em-dashes, quotes, etc... because sometimes they work.
So, how do I implement a function to correct these characters, or rewrite them as ascii BEFORE they are written into the database? And, do you have a Function I could use? |
Edited by - Astralis on 12 December 2004 18:04:40 |
|
dayve
Forum Moderator
    
USA
5820 Posts |
Posted - 12 December 2004 : 18:43:54
|
I thought I answered this for you? The Replace function can be used to create the filters you need. Just apply the function to the values going into the database in your INSERT and UPDATE sql statements. |
|
 |
|
Astralis
Senior Member
   
USA
1218 Posts |
Posted - 12 December 2004 : 18:49:29
|
Yeah, that's what I was looking at. Should there be more characters added to it?
How do I apply it? It may seem obvious, but I'm dealing with some ridiculous Dreamweaver code.
Would you take a look at this mess and tell me how to do it?
<%
editAction = CStr(Request("URL"))
If (Request.QueryString <> "") Then
editAction = editAction & "?" & Request.QueryString
End If
abortEdit = false
editQuery = ""
If (CStr(Request("insert")) <> "") Then
editConnection = articleConn_STRING
editTable = "articles"
editRedirectUrl = "admin_list_inactive.asp"
fieldsStr = "REMOVED FOR LENGTH"
columnsStr = "REMOVED FOR LENGTH"
fields = Split(fieldsStr, "|")
columns = Split(columnsStr, "|")
For i = LBound(fields) To UBound(fields) Step 2
fields(i+1) = CStr(Request.Form(fields(i)))
Next
If (editRedirectUrl <> "" And Request.QueryString <> "") Then
If (InStr(1, editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
editRedirectUrl = editRedirectUrl & "?" & Request.QueryString
Else
editRedirectUrl = editRedirectUrl & "&" & Request.QueryString
End If
End If
End If
%>
<%
If (CStr(Request("insert")) <> "") Then
tableValues = ""
dbValues = ""
For i = LBound(fields) To UBound(fields) Step 2
FormVal = fields(i+1)
typeArray = Split(columns(i+1),",")
Delim = typeArray(0)
If (Delim = "none") Then Delim = ""
AltVal = typeArray(1)
If (AltVal = "none") Then AltVal = ""
EmptyVal = typeArray(2)
If (EmptyVal = "none") Then EmptyVal = ""
If (FormVal = "") Then
FormVal = EmptyVal
Else
If (AltVal <> "") Then
FormVal = AltVal
ElseIf (Delim = "'") Then ' escape quotes
FormVal = "'" & Replace(FormVal,"'","''") & "'"
Else
FormVal = Delim + FormVal + Delim
End If
End If
If (i <> LBound(fields)) Then
tableValues = tableValues & ","
dbValues = dbValues & ","
End if
tableValues = tableValues & columns(i)
dbValues = dbValues & FormVal
Next
editQuery = "insert into " & editTable & " (" & tableValues & ") values (" & dbValues & ")"
'Response.Write editQuery
'Response.End
If (Not abortEdit) Then
Set editCmd = Server.CreateObject("ADODB.Command")
editCmd.ActiveConnection = editConnection
editCmd.CommandText = editQuery
editCmd.Execute
editCmd.ActiveConnection.Close
If (editRedirectUrl <> "") Then
Response.Redirect(editRedirectUrl)
End If
End If
End If
%>
|
Edited by - Astralis on 12 December 2004 20:57:25 |
 |
|
dayve
Forum Moderator
    
USA
5820 Posts |
Posted - 12 December 2004 : 19:06:02
|
ahhh, the dreaded bloated code that DW spits out... I would apply the function after this line:
FormVal = "'" & Replace(FormVal,"'","''") & "'"
FormVal = CleanText(FormVal)
CleanText equals the name of your function.
You can eliminate the line above it if your CleanText function takes care of the single quote issues.
|
|
Edited by - dayve on 12 December 2004 19:09:29 |
 |
|
Astralis
Senior Member
   
USA
1218 Posts |
Posted - 12 December 2004 : 19:10:56
|
Thanks dayve! You and everyone here are always very helpful. |
 |
|
Astralis
Senior Member
   
USA
1218 Posts |
Posted - 12 December 2004 : 20:08:13
|
Well, that code is not likeing the replace function. When I try to update the DB, I get this error:
Microsoft JET Database Engine error '80040e14'
Syntax error (missing operator) in query expression 'þParliamentary Glossaryþ'. I'm not sure why the red is getting converted.
/admin/admin_update.asp, line 89
The "Parliamentary Glossary" is the title to the article and I can see that the replace function is somehow replacing characters in the update query. Do you know why?
|
Edited by - Astralis on 12 December 2004 20:09:43 |
 |
|
dayve
Forum Moderator
    
USA
5820 Posts |
Posted - 12 December 2004 : 20:27:54
|
can you post a text version of admin_update.asp and your CleanText function? |
|
 |
|
Astralis
Senior Member
   
USA
1218 Posts |
Posted - 12 December 2004 : 20:56:22
|
Dayve,
Yes. I'll do that. I do want to figure out how to do that. But, first. I should tell you the work-around that I did. I don't understand it. I remembered that I use the system on a different site and all the characters come through without any problem. But, for some reason on this site that I'm working on, it didn't work. So, I looked at the Meta Tags to see what the difference was because that's the only explaination.
On the good site, it shows this:
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
On the bas site, is shows this:
<META http-equiv=Content-Type content="text/html; charset=ISO-8859-15">
So, I replaced the bad with the good and it works! I don't understand it and I wonder if it will work on other computers. Can you explain why it works and if this can be a permanent work-around? |
 |
|
D3mon
Senior Member
   
United Kingdom
1685 Posts |
Posted - 13 December 2004 : 04:54:21
|
I think this is what you're looking for:
'replaces non-sgml characters e.g. when content copy/pasted in from MS Word
strResult = replace(strResult,chr(133),"#8230;")
strResult = replace(strResult,chr(134),"#8224;")
strResult = replace(strResult,chr(135),"#8225;")
strResult = replace(strResult,chr(136),"#710;")
strResult = replace(strResult,chr(139),"#8249;")
strResult = replace(strResult,chr(145),"#8216;")
strResult = replace(strResult,chr(146),"#8217;")
strResult = replace(strResult,chr(147),"#8220;")
strResult = replace(strResult,chr(148),"#8221;")
strResult = replace(strResult,chr(150),"#8211;")
strResult = replace(strResult,chr(151),"#8212;")
strResult = replace(strResult,chr(152),"#732;")
strResult = replace(strResult,chr(153),"#8482;")
strResult = replace(strResult,chr(155),"#8250;")
|
 Snitz 'Speedball' : Site Integration Mod : Friendly Registration Mod "In war, the victorious strategist only seeks battle after the victory has been won" |
 |
|
Astralis
Senior Member
   
USA
1218 Posts |
Posted - 13 December 2004 : 17:12:55
|
Thanks D3mon. Will this be used to input data in the database or to read it from the database? Do you recommend I keep this: "charset=windows-1252" on the admin page? |
 |
|
D3mon
Senior Member
   
United Kingdom
1685 Posts |
Posted - 13 December 2004 : 17:50:41
|
This would be run on the input data before it is entered into the DB.
Stick with the: charset=ISO-8859-15 - You can't assume your site will always be viewed using a Windows-based browser. |
 Snitz 'Speedball' : Site Integration Mod : Friendly Registration Mod "In war, the victorious strategist only seeks battle after the victory has been won" |
 |
|
|
Topic  |
|