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

Glenn

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

chrishirst

Well-Known Member
Staff member
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.
 

Glenn

Member
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:

Glenn

Member
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:

chrishirst

Well-Known Member
Staff member
It is saving it in the database as just & but somehow it is echoing it out as &amp;

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.
 

Glenn

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

chrishirst

Well-Known Member
Staff member
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.

What is it you are calling "straight into the database"?

And what is then extracting it from the database?
 

Glenn

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

chrishirst

Well-Known Member
Staff member
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.
 

Glenn

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

chrishirst

Well-Known Member
Staff member
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.
 
Top