| Author |
Message |
rajasekar Forum Regular
Joined: 30 May 2004 Posts: 445 Location: Nothing but Net
|
Posted: Fri Nov 09, 2007 5:50 am Post subject: String in PHP |
|
|
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
|
Posted: Fri Nov 09, 2007 5:54 am Post subject: |
|
|
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
|
Posted: Fri Nov 09, 2007 7:06 am Post subject: |
|
|
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
|
Posted: Fri Nov 09, 2007 7:33 am Post subject: |
|
|
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
|
Posted: Fri Nov 09, 2007 8:30 am Post subject: |
|
|
| 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
|
|
| Back to top |
|
| |
|
|
|