SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Thread: Saving as & intsead of &

  1. #1
    SitePoint Evangelist
    Join Date
    Jan 2005
    Location
    UK
    Posts
    537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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...?

  2. #2
    Grüße aus'm Pott
    SitePoint Award Recipient Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    2,744
    Mentioned
    47 Post(s)
    Tagged
    3 Thread(s)
    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?
    How well do you know your JavaScript from your jQuery?
    Check out SitePoint's latest JavaScript challenge


    My blog

  3. #3
    SitePoint Evangelist
    Join Date
    Jan 2005
    Location
    UK
    Posts
    537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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 "&"

  4. #4
    Hosting Advisor silver trophybronze trophy
    SitePoint Award Recipient cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    2,961
    Mentioned
    49 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by skyline View Post
    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.

  5. #5
    SQL Consultant silver trophybronze trophy
    SitePoint Award Recipient r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    38,513
    Mentioned
    35 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by skyline View Post
    ..could this be a mysql update or configuration issue or...?
    not mysql

    likely a php function
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  6. #6
    SitePoint Evangelist
    Join Date
    Jan 2005
    Location
    UK
    Posts
    537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  7. #7
    Hosting Advisor silver trophybronze trophy
    SitePoint Award Recipient cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    2,961
    Mentioned
    49 Post(s)
    Tagged
    0 Thread(s)
    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.

  8. #8
    SitePoint Evangelist
    Join Date
    Jan 2005
    Location
    UK
    Posts
    537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Homemade CMS! Tracked down the problem, htmlspecialchars being applied. Doh!

  9. #9
    Hosting Advisor silver trophybronze trophy
    SitePoint Award Recipient cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    2,961
    Mentioned
    49 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by skyline View Post
    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •