Update query failing because of ' apostrophes.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
arunkar
Forum Commoner
Posts: 50
Joined: Mon Feb 25, 2008 10:37 pm

Update query failing because of ' apostrophes.

Post by arunkar »

Hi folks,

I'm doing a simple update with the below code:

Code: Select all

         $queryUpdate = "UPDATE tbl_projects SET ProjectTitle='$pjTitle', ProjectCostUSD='$pjCostUSD', ProjectRegionID='$pjRegionID', ProjectCountry='$pjCountryID', ProjectCatID='$pjCategoryID',  ProjectBeneficiaryID='$pjBeneficiaryID', ProjectStory='$pjStory', ProjectProjectURL='$pjURL', ProjectLIVE='0', ProjectEdit='1', ProjectDelete='0', ProjectLastUpdatedDate='$currentDate' WHERE ProjectID='$projID' AND ProjectOrgJosUserID='$DelOrgID' ";
         echo "$queryUpdate <br><br>";
        mysql_query($queryUpdate);
 
This is what is written into the database. My Php is getting confused with ' (apostrophes), in the ProjectStory field below.

How do I over come this? Any ideas folks?

Code: Select all

 
UPDATE tbl_projects SET ProjectTitle='STOP Global Warming', ProjectCostUSD='78999.99', ProjectRegionID='3', ProjectCountry='US', ProjectCatID='4', ProjectBeneficiaryID='9', ProjectStory='
Global warming already disrupts millions of lives daily in the forms of destructive weather patterns and loss of habitat.
 
What is already happening is only the tip of the melting iceberg, for it is our children and grandchildren who may suffer most from the effects of global warming. Hundreds of millions of people may be exposed to famine, water shortages, extreme weather conditions and a 20 - 30% loss of animal and plant species if we don't reduce the rate of global warming and reduce GHG emissions'. ', ProjectProjectURL='http://www.globalwarming.org', ProjectLIVE='0', ProjectEdit='1', ProjectDelete='0', ProjectLastUpdatedDate='2008-09-25' WHERE ProjectID='7707' AND ProjectOrgJosUserID='944'
 
thanks guys
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Update query failing because of ' apostrophes.

Post by onion2k »

Escape your data with mysql_real_escape_string(). Read the PHP manual page for how to use it properly.
Post Reply