|
-
Mar 21st, 2006, 12:39 AM
#1
Thread Starter
PowerPoster
Save "'" in MySQL database
I have names like O'Brien and O'Keefe that I need to save in my MySQL database but it throws up an error because of the "'".
How can I over come this as I don't want to save name like OBrien and OKeefe?
Thanks.
-
Mar 21st, 2006, 01:05 AM
#2
Re: Save "'" in MySQL database
Before saving you may try to replace those single quotes into two single quotes....
VB Code:
Public Function CleanText(ByVal pString As String) As String
CleanText = Replace$(pString, "'", "''")
End Function
Oooppsss... I just realized this is in PHP...
-
Mar 21st, 2006, 02:21 AM
#3
Thread Starter
PowerPoster
Re: Save "'" in MySQL database
At least you tried
-
Mar 21st, 2006, 02:22 AM
#4
Re: Save "'" in MySQL database
Have you tried replacing the single quote with PHP code before saving?
-
Mar 21st, 2006, 02:40 AM
#5
Thread Starter
PowerPoster
Re: Save "'" in MySQL database
I could replace each ' with "" before saving but then I wouldn't know which name contains a ' and which ones don't (eg O'Brien)
-
Mar 21st, 2006, 02:44 AM
#6
Re: Save "'" in MySQL database
In VB6.0 I use to use the function I posted earlier in every string I'll save to the database, I don't know any PHP but perhaps you could use a parameterized query, that way it would be safer against sql injections also...
-
Mar 21st, 2006, 03:20 AM
#7
Re: Save "'" in MySQL database
Backslash escape it
\'
If you don't have magic quotes on (which it is by default) then you can use addslashes() to escape an input string for you.
-
Mar 21st, 2006, 03:22 AM
#8
Re: Save "'" in MySQL database
have you tried using which returns the ' character?
-
Mar 21st, 2006, 03:23 AM
#9
Frenzied Member
Re: Save "'" in MySQL database
lintz:
You have to escape the single quote by putting a backslash in front of it.
O\'Brien.
You will also need to use the MySQL functions AddSlashes and StripSlashes when storing (AddSlashes) and retrieving (StripSlashes) the data into and out of your MySQL database.
I would suggest you check out the online MySQL Manual at: http://dev.mysql.com/doc/refman/5.0/en/
Good Luck
-
Mar 21st, 2006, 03:35 AM
#10
Re: Save "'" in MySQL database
You do not need to use the stripslashes function when retrieving the data.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|