FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


PHP/MySQL: Apostrophe problem





frozenhead
Need little help here.

Lets say I have this sql statement where I need to update a field with a apostrophe on it, like:

Code:

sql_query = "update TABLE1 SET Field1 = 'It's me'''; //updating Field1 with a value = It's me
mysql_query(blah blah...


It'll give me a syntax error.

How will I fix it?, Anyone? . Thanks in advance. Smile
Rhysige
I suggest you think about this alot in future because not doing this will leave you open to database editing more than you can believe. make 'It's Me'
$string = 'It's me';

then you use
$escapedstring = mysql_real_escape_string($string);

then use $escapedstring in your query.
This will basically addslahses to all ' in the string.
kacembay
Well i learnt how to use php at http://www.php.net/

Its a good site to learn straight from the basics to all the advanced stuff.
Nyizsa
Try using double quotes when your string includes a single one and vica versa. For example:
Code:
$string="it's me";

Or you can try to escape it. (It is just an idea, might not work.)
Related topics
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.