borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (URGENT!!! select date1 until date2 and more field Help Please...)Next Topic (Image Sql?) New Topic New Poll Post Reply
AndreaVB Forum : Database : INSERT INTO statement : MySQL
Poster Message
CLIPER
Level: Big Cheese

Registered: 26-07-2005
Posts: 27

icon INSERT INTO statement : MySQL

Hi guys,

I am just curious if there is a good way/standard procedure on how to prevent ambiguous characters that will be inserted and queried in your database.

Like for example, I have a user inputted a paragraph like this one in my forum.

testing insert invalid characters "','" & test & "','" &%^@#$(%@^)

Well, for me, it will give a problem without replacing/cleaning the "','" chars. when using it in our INSERT INTO statement.


So what I do right now is encrypt the data. I dont use the Replace() or any good functions to clear that up.

So Any of you wants to post same learning and problem here? Thank you in Advance.


Regards,

Mark

____________________________
CLIPER

15-05-2006 at 05:04 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
admin
Level: Administrator


Registered: 04-04-2002
Posts: 532
icon Re: INSERT INTO statement : MySQL

MySQL and MS-SQL accept these special characters in text queries but they need to have a backslash character before special characters...so before concatenating the text with what's written by the user you should use a function do add backslashes.


Public Function AddSlashes(ByVal strText As String) As String
    'escape the single Backslash
    strText = Replace(strText, "\", "\\")
    'escape single quote
    strText = Replace(strText, "'", "\'")
    'escape double quote
    strText = Replace(strText, """", "\""")
    AddSlashes = strText
End Function


let me know if it works...

____________________________
AndreaVB

07-06-2006 at 07:49 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
AndreaVB Forum : Database : INSERT INTO statement : MySQL
Previous Topic (URGENT!!! select date1 until date2 and more field Help Please...)Next Topic (Image Sql?) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder