If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Advice Me: which characters can make insert go wrong

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-02-05, 00:46
bobd303 bobd303 is offline
Registered User
 
Join Date: Dec 2003
Location: Gandhinagar India
Posts: 22
Lightbulb Advice Me: which characters can make insert go wrong

hi,
I am creating a jsp app which will add some data to mysql tables.. Now if we enter some characters like single quote(') it will create error while inserting/updating the db..
I would like to know what can i do for that.. Also what all characters like single quotes can create problem in updation of db..
thanks
__________________

Last edited by bobd303; 02-02-05 at 00:49.
Reply With Quote
  #2 (permalink)  
Old 02-02-05, 06:27
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
single quote is the only problem

replace each single quote in the text with two consecutive single quotes

e.g. to insert the name O'Toole,

insert into names (name) values ( 'O''Toole' )
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 02-02-05, 06:33
bobd303 bobd303 is offline
Registered User
 
Join Date: Dec 2003
Location: Gandhinagar India
Posts: 22
Thumbs up

thanks buddy
__________________
Reply With Quote
  #4 (permalink)  
Old 02-07-05, 22:07
rbstern rbstern is offline
Registered User
 
Join Date: Feb 2005
Posts: 8
It is good practice, anytime you update or insert strings into a SQL database, to pass the values through a function that handles the quotes. Example, in ASP I do something this:

function f_SafeQuotes(inputstring)
f_SafeQuotes = replace(inputstring," ' ", " '' ")
end function

...

conn.execute "insert into test (ID,name) values (1," & f_SafeQuotes(namevar) & ")"
Reply With Quote
  #5 (permalink)  
Old 02-08-05, 09:03
bobd303 bobd303 is offline
Registered User
 
Join Date: Dec 2003
Location: Gandhinagar India
Posts: 22
that is a good idea.. infact now i am doing the same.. thanks
__________________
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On