code from database not working...

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
khuti
Forum Newbie
Posts: 13
Joined: Mon Mar 06, 2006 12:29 am

code from database not working...

Post by khuti »

hi, im having a spot of trouble..

ive made a mysql database with a field in a table to show all data for that page.

thing is i have a peice of code in it <?=$email?> to display an email address. but it wont work. when i put the code straight on the page without the use of the database it works fine. so im guessing this is probably sum sort of security thing?

well can anybody help me around this? maybe i could use different tags like [?$email?] and get it to translate the new brackets to the originals? if so how would i go about doing this?

any help will be muchly appreciated as im kinda stuck now!

thanks in advance..

khuti
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

This will probably not work the way you want because you are using a string output from the database. PHP isn't go to parse this through the engine because it is coming out of the database as a string, not as code.

There are a few things you can do about this. I would like at using something like sprintf or str_replace. Of course, this would mean that you would have to set vars first and use those vars as replacements within your database content. But I think you get the picture.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

post your code.
khuti
Forum Newbie
Posts: 13
Joined: Mon Mar 06, 2006 12:29 am

Post by khuti »

hi, thanks for fast response..

only thing is i dont quite understand sprintf thingy, i clicked them from ur msg but im a little lost to tell u the truth!

my page has this on it..

<?
$result = mysql_query("SELECT * FROM page");
if($row = mysql_fetch_array($result)){
echo($row['data']);
}
?>

and the <?=$email?> is inside the $row['data'] the email var is set up at top of the top so it should know what to fill it in as. basically the whole page of info is inside the $row['data'].

i cant see how i would use the sprintf into that.. sorry to be a pain!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You've stored the page code inside $row['data'] ? eval() or regex are the only options there then. I'd avoid eval() like the plague.
khuti
Forum Newbie
Posts: 13
Joined: Mon Mar 06, 2006 12:29 am

Post by khuti »

how comes?

i couldnt think of any other way to do it.. its for a basic cms, to allow them to change the info on their contact page but as they dont know much about html ive made it so they can update their email address in another table, then then the <?=$email?> should display the email address as a link for them. is there a better way to do this then?

also eval hasnt worked.. im getting

Parse error: parse error, unexpected '<' in /home/adrianbr/public_html/falconhotel/contact.php(85) : eval()'d code on line 1
khuti
Forum Newbie
Posts: 13
Joined: Mon Mar 06, 2006 12:29 am

Post by khuti »

hey guys thanks for your help. especially the speed of it!!

anyway i managed to solve the problem with the str_replace function that was mentioned. worked like a dream when i used it properly!

thanks peeps,

khuti
Post Reply