Saving as & intsead of &

I have a basic php/mysql cms. When I go to save a textfield that contains the char “&” it seems to be updating the database with “&”
I’m sure it suddenly started happening, could this be a mysql update or configuration issue or…?

Hi there,

This might be an encoding issue.

Let me understand your problem:
You have a CMS.
You enter text into your CMS (for example to update a page on your site).
You save your changes.
You look at your website and see that the & characters which you entered in the CMS are being displayed as &

Is that correct?

No, it’s the text that is actually updated to the database that is converted to the &
The text field has “&”, the updated table contains “&”

Right, because the CMS is likely encoding it to be stored into the database. When it is read from the database, the & is the appropriate HTML entity for displaying purposes.

Granted, it is unnecessary to encode & in a database, but it is absolutely necessary to encode it when writing it as output for a user to see on your site.

not mysql

likely a php function

Thanks guys, I’ll look into the php then… just wanted to rule out mysql. Strange how it’s suddenly started happening, almost like a version update of php or mysql had triggered the change in processing

Have you recently upgraded the CMS? Could be part of the CMS upgrade. On a side note, I’ve asked that this thread be moved to the PHP forum.

Homemade CMS! Tracked down the problem, htmlspecialchars being applied. Doh!

That would do it. It is true that you DO NOT need to do that when inserting into the database, but you SHOULD be doing that when you are writing the database values to the page for a user to see.