Lifelesspeople.com

 Forum FAQsForum FAQs  Knowledge BaseKnowledge Base  RulesRules   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   HostingHosting   RegisterRegister 
 DonateDonate   WikiWiki   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

String in PHP

 
Lifelesspeople.com Forum Index -> Web Architects' Abode
Post new topic   Reply to topic View previous topic :: View next topic  
Author Message
rajasekar
Forum Regular


Joined: 30 May 2004
Posts: 445
Location: Nothing but Net

PostPosted: Fri Nov 09, 2007 5:50 am    Post subject: String in PHP Reply with quote

Hi,

The question:
How to process a text to mysql database if it contains a single quote? eg: "This is my friend's book"

The problem:
I have inserted a text with single quots into a table. This works well. Again I retrieved the info from that table and insert into another one using insert statement, the record not get inserted and not even display an error.

Please help me. Thank you!
_________________
Free Online Classifieds - Reach thousands of users world-wide!
[img:0a37bba199]http://www.freelineads.com/banners/banner01.gif[/img:0a37bba199]
Back to top
 
krt
...


Joined: 11 Jan 2005
Posts: 4695
Location: Down Under

PostPosted: Fri Nov 09, 2007 5:54 am    Post subject: Reply with quote

Escape with a backslash, e.g. "my friend\'s book"

Or use the recommended mysql_real_escape_string()
Code:
$var = mysql_real_escape_string("This is my friend's book");
mysql_query("INSERT INTO table VALUES('$var');") or die(mysql_error());


It wasn't returning an error because you didn't tell it to. You have to explicitly do so with mysql_error() or working with the query after executing.
Back to top
 
rajasekar
Forum Regular


Joined: 30 May 2004
Posts: 445
Location: Nothing but Net

PostPosted: Fri Nov 09, 2007 7:06 am    Post subject: Reply with quote

This won't works again. This mysql_real_escape_string("My friend's book")
gives "My friends/'s book" and this string not get inserted into a mysql table. The solution is I want to remove completely the " ' " single quote in "Myfriend's book" string. Any function or code snippet for this?

eg: My friend's book => My friends book

That's all.
_________________
Free Online Classifieds - Reach thousands of users world-wide!
[img:0a37bba199]http://www.freelineads.com/banners/banner01.gif[/img:0a37bba199]
Back to top
 
krt
...


Joined: 11 Jan 2005
Posts: 4695
Location: Down Under

PostPosted: Fri Nov 09, 2007 7:33 am    Post subject: Reply with quote

Don't make sacrifices because you can't be bothered getting it to work property. That is the laziness that causes the crap that is the majority of software out there these days.

Can you show me the code where it "isn't working"?

If you must, use str_replace('\'', '', $string);. BTW, haven't you been using PHP for awhile now? Just wondering as these are very basic issues.
Back to top
 
axyjo
Experienced Poster


Joined: 30 Aug 2005
Posts: 56


PostPosted: Fri Nov 09, 2007 8:30 am    Post subject: Reply with quote

Like krt said.. str_replace will just replace them while storing the values into the database.. When you want to retrieve the values again, it won't show the apostrophe again.
Back to top
 
rajasekar
Forum Regular


Joined: 30 May 2004
Posts: 445
Location: Nothing but Net

PostPosted: Sat Nov 10, 2007 6:09 am    Post subject: Reply with quote

At last I got it working! I was using

htmlspecialchars("This is my friend's book", ENT_QUOTES)

and send the info to database. Record inserted well.
_________________
Free Online Classifieds - Reach thousands of users world-wide!
[img:0a37bba199]http://www.freelineads.com/banners/banner01.gif[/img:0a37bba199]
Back to top
 
Display posts from previous:   
Post new topic   Reply to topic    Lifelesspeople.com Forum Index -> Web Architects' Abode All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Home | Hosting | News | Forum | Links | System Status | About | Archive | Donate ]
Powered by phpBB © 2001, 2002 phpBB Group
All trademarks and copyrights on this page are owned by their respective owners. Posts and comments are owned by the poster. Everything else © 2001 - 2007 Lifelesspeople.com