Forum Moderators: coopster

Message Too Old, No Replies

Symbols In MySQL and Manipulation in PHP

         

bobbonew

5:30 pm on May 29, 2009 (gmt 0)

10+ Year Member



Hey guys, just noticed this craziness going on with my database. Apparently when I store information in my database, this is what is in the textarea:

    What's better classical music or new age music?

which gets stored in mysql as:

    What's better classical music or new age music?

And when I select it from a database and print it to the page it shows up as this (even in the view source):

    What's better classical music or new age music?


I have never noticed this behavior before, and now I'm having multiple problems. When I go and run a function to remove any symbols (not numbers or characters), this is what prints to the screen:

    What39s better classical music or new age music

I know nothing about character sets. That field is apparently set to "latin1_swedish_ci". Also, when I do substr() for 5 character, it outputs like: What&

If I send an email with php with that as the body, it says

    What's better classical music or new age music?

I'm at my whits end googling, whenever I type in ' it converts it to symbol! Any help or insights! This has never been a problem to me nor have I noticed it as I have always just printed the data and lived with the substr() problem. Thanks.

idfer

9:07 pm on May 29, 2009 (gmt 0)

10+ Year Member



It looks like you're passing the data through htmlentities() or htmlspecialchars() before you insert it into the DB. Try adding some debugging code to display the raw input data (e.g. the contents of $_REQUEST if the data is coming from a form) and the SQL statement used to store the data.

But be careful if you use a simple echo for debugging, since you're dealing with HTML entities the browser will translate the entities for you before displaying them, so you need to look at the page's HTML source to see the real values.

Hope this helps.