Page 1 of 1
code from database not working...
Posted: Mon Mar 06, 2006 12:35 am
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
Posted: Mon Mar 06, 2006 12:54 am
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.
Posted: Mon Mar 06, 2006 12:55 am
by feyd
post your code.
Posted: Mon Mar 06, 2006 1:06 am
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!
Posted: Mon Mar 06, 2006 1:14 am
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.
Posted: Mon Mar 06, 2006 1:22 am
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
Posted: Mon Mar 06, 2006 1:54 am
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