How do I save code in a database and have it spit it back out without changing it?

Discussion in 'Programming' started by Glenn, Jun 8, 2015.

to remove all ads.
  1. Glenn

    Glenn Member

    Messages:
    202
    I am copying code from a site that generates it for me to use as an affiliate to selling items. Sometimes the code gets changed and what I see in the end result isn't what I started with. I'm using php and mysql.
     
  2. chrishirst

    chrishirst Well-Known Member Staff Member

    Messages:
    2,668
    Find out what is "changing" it and make it stop.
     
  3. Glenn

    Glenn Member

    Messages:
    202
    That's why I'm posting my question.
     
  4. chrishirst

    chrishirst Well-Known Member Staff Member

    Messages:
    2,668
    And if you were expecting any other answer to your question, ....


    ....

    We need to know EXACTLY what the process is before we can even make a guess at what the 'problem' is..

    And by exactly I mean the whole process, start to finish.
     
  5. Glenn

    Glenn Member

    Messages:
    202
    This is what I copy:
    <iframe style="width:120px;height:240px;" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" src="//ws-na.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=US&source=ss&ref=ss_til&ad_type=product_link&tracking_id=campscorne-20&marketplace=amazon&region=US&placement=B003OBFECG&asins=B003OBFECG&linkId=5WI3CSFCGAHXL2LR&show_border=true&link_opens_in_new_window=true">
    </iframe>

    I save it after setting that to a variable by:
    mysql_query("INSERT INTO weblinks (catid, title, url, description, ordering, published) VALUES ('$catid', '$title', '$url', '$description', '$ordering', '$published') ");

    After reading it from the database I send it to the page by:
    echo nl2br($description), "\n";


    This is what it is changed to:
    <iframe style="width:120px;height:240px;" marginwidth="0" marginheight="0" scrolling="no" src="//ws-na.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&amp;OneJS=1&amp;Operation=GetAdHtml&amp;MarketPlace=US&amp;source=ss&amp;ref=ss_til&amp;ad_type=product_link&amp;tracking_id=campscorne-20&amp;marketplace=amazon&amp;region=US&amp;placement=B003OBFECG&amp;asins=B003OBFECG&amp;linkId=B6DCXYDKWI7NLMVZ&amp;show_border=true&amp;link_opens_in_new_window=true" frameborder="0"><br />
    </iframe>
     
    Last edited: Jun 8, 2015
  6. Glenn

    Glenn Member

    Messages:
    202
    Looks like the problem is with the ampersand.

    It is saving it in the database as just & but somehow it is echoing it out as &amp;
     
    Last edited: Jun 8, 2015
  7. chrishirst

    chrishirst Well-Known Member Staff Member

    Messages:
    2,668
    Probably not, will you be telling us WHAT you paste the code into??

    Then we can then tell you that it is whatever WYSIWYG editor you are using.
     
  8. Glenn

    Glenn Member

    Messages:
    202
    I'm not using a WYSIWIG
     
  9. Glenn

    Glenn Member

    Messages:
    202
    I copied the code and pasted it straight into the database and it did the same thing so that is what is has to be doing.
     
  10. ronaldroe

    ronaldroe Super Moderator Staff Member

    Messages:
    1,223
  11. chrishirst

    chrishirst Well-Known Member Staff Member

    Messages:
    2,668
    What is it you are calling "straight into the database"?

    And what is then extracting it from the database?
     
  12. Glenn

    Glenn Member

    Messages:
    202
    Using phpmyadmin.

    I'm using php to extract it before echoing it into the web page.
     
  13. Glenn

    Glenn Member

    Messages:
    202
    Now I have discovered that if I only have a few of these on a page they are fine but when I start having several some start messing up. What could be causing this?
     
  14. chrishirst

    chrishirst Well-Known Member Staff Member

    Messages:
    2,668
    Something is 'cleaning up' the code, but without seeing the PHP code that you are using ... ... no one is going to be able to tell you what it is or where it is.
     
  15. Glenn

    Glenn Member

    Messages:
    202
    I think have have narrowed down the problem. When I edit it, I have the description in a text area and when I have something like &reg it shows up as ® so when I save my edit, it changes things like this.
     
  16. chrishirst

    chrishirst Well-Known Member Staff Member

    Messages:
    2,668
    That's just the display for the HTML entity, something else has to change the ampersand into the HTML entity code &amp ; a text area doesn't have that kind of functionality.
     
  17. Glenn

    Glenn Member

    Messages:
    202
    Yes, it does. I got it. echo htmlspecialchars($srt) worked.
     
  18. chrishirst

    chrishirst Well-Known Member Staff Member

    Messages:
    2,668
    Nope, it is the code that the text area submits the data to, that does any modification.
     
  19. Glenn

    Glenn Member

    Messages:
    202
    Yes, it worked. It fixed my problem.
     
  20. web based codin

    web based codin New Member

    Messages:
    4
    html entities function might help also

    or send it into database base64 then decode it when you retrieve it
     

Share This Page