Retrieving HTML code stored in a database.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
john_crawford32
Forum Newbie
Posts: 9
Joined: Mon Mar 31, 2003 7:56 pm
Location: East Berlin, PA
Contact:

Retrieving HTML code stored in a database.

Post by john_crawford32 »

HI All,
I have a database with 2 tables.
1 stores html code in a blob that might include text images calls etc.
the other table stores either text or an image call "<img src="images/ads/applehunts.jpg">
in a varchar field.

The blob works fine.
If I store text in the varchar field it is fine but if I store
<img src="images/ads/applehunts.jpg"> in the varchar field I get nothing with this code

Code: Select all

echo $row&#1111;"Info"];
if I use this code

Code: Select all

$mystring = htmlspecialchars($row&#1111;"Info"]);
echo $mystring;
I get
<img src="images/ads/applehunts.jpg">
but no image.
Do I have to use a blob to store html code?
or am I doing something wrong?
Can I change the field type without loosing data?
Thanks
John
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

What do you get in the source of the page when you just do:

Code: Select all

echo $row["Info"];
Mac
HITMAN1net
Forum Newbie
Posts: 4
Joined: Wed Apr 02, 2003 1:49 pm
Location: england
Contact:

Post by HITMAN1net »

You would expect what you got for your second attempt though.

The first one should work really. I'm going to end up repeating what john_crawford32 said so I'll just stop there. More info?

---
Ben
john_crawford32
Forum Newbie
Posts: 9
Joined: Mon Mar 31, 2003 7:56 pm
Location: East Berlin, PA
Contact:

Post by john_crawford32 »

Here is what I get with

Code: Select all

echo $row&#1111;"Info"];

Code: Select all

<tr><td><HR><BR><BR><BR><BR><a href=' mailto:applebucks@superpa.net' target='blank'>visit their website</a></td></tr>
This is what I get with htmlspecialchars

Code: Select all

<tr><td><HR><BR><BR><BR><img src="images/ads/applehunts.jpg"><BR><a href=' mailto:applebucks@superpa.net' target='blank'>visit their website</a></td></tr>r>
It is strange because there is no error no space just blank.
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

You can can use normal TEXT field in the database, keep your HTML in there, and then to include it in a webpage you simply grab it from the database (I'm sure you know how) and then get it into the page using this..

Code: Select all

<?php
echo(stripslashes($row[html]));
?>
..for example.

It's something I've been using recently and it seems to work fine.
john_crawford32
Forum Newbie
Posts: 9
Joined: Mon Mar 31, 2003 7:56 pm
Location: East Berlin, PA
Contact:

Strange but True

Post by john_crawford32 »

I don't understand.
I was experimenting and noticed if I put the photo in a different directory it worked. So I deleted the directory and readded it.
Still didn't work.
then I changed the directory name from ads to dds and it works fine.
What confuses me is that the code doesn't show up.
is "ads" a php function?
Post Reply