skyline — 2012-12-13T07:14:47-05:00 — #1
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...?
pullo — 2012-12-13T08:29:06-05:00 — #2
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?
skyline — 2012-12-13T08:39:56-05:00 — #3
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 "&"
cpradio — 2012-12-13T08:41:30-05:00 — #4
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.
r937 — 2012-12-13T08:48:28-05:00 — #5
likely a php function
skyline — 2012-12-13T08:51:39-05:00 — #6
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
cpradio — 2012-12-13T08:56:44-05:00 — #7
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.
skyline — 2012-12-13T09:00:45-05:00 — #8
Homemade CMS! Tracked down the problem, htmlspecialchars being applied. Doh!
cpradio — 2012-12-13T09:54:23-05:00 — #9
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.