hi there! i'm having a difficulting inserting a data on the database wherein data that is being entered has an apostrophe. how do you fix this one? my code is below $query = " insert into photos (date, photo_url , photo_description) values ('$frm_date','$frm_photo_url','$frm_photo_description')" ; PHP: and everytime i run this one an error is directed on the $frm_photo_description how do i get by with the apostrophe?
what is the exact error? I don't think it's the apostrophe that is messing you up as you have apostrophes placed before that but it doesn't give an error on those. EDIT ----- I didn't get what you were saying but, thanks to Lordy below, I realize you are talking about the actual data that is set in the variable . Lordy is right, the alternative is making the field (in your DB) a text field or "blob" or something similar (can't remember exactly what it's called on SQL)
your gonna need to insert it with an escape (\) best way would be to first explode $frm_photo_description based on ' and then implode with \'
hello im trying to put this text Whether it's for sale or as giveaways, City has enough for everybody. Vendors sell cheap vegetables on the road every afternoon at the Agdao Public Market. and it produces this error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's for sale or as giveaways, City has enough for everybody. Vendors sell cheap ve' at line 3
Instead of exploding and imploding as per Lordy's suggestion (which is assuming that the ONLY problems are with single quotes...) you should use the mysql_real_escape_string function.
$query = " insert into photos (date, photo_url , photo_description) values ('$frm_date','$frm_photo_url',mysql_real_escape_string($frm_photo_description))"; PHP:
Try this: $query = " insert into photos (date, photo_url , photo_description) values ('$frm_date','$frm_photo_url','" . mysql_real_escape_string($frm_photo_description) . "')"; PHP: When you want to redisplay the content use stripslashes() Brew