My PHP code outputs a field from a SQL Database table and in that field I have this code at the end: <?php echo '<a href="printlegal.php?pageid=' . urlencode($_GET['pageid']) . '" class="bodynav">Printer Friendly Version</a>'; ?>
Everything else shows up except that. What am I doing wrong?
You can't do it that way, what you have to do is have your file with a .php extension but open and close php when u need it ...
for example
<a href="bleh.php?page=<?php // whatever u need in here ?> ">Click here</a>
Understand? Simple escape in and out of php embedded in your html ....
Nah...you can just do it like this...
<?php $pageid = urlencode($_GET['pageid']); print"<a href=\"printlegal.php?pageid=$pageid\" class=\"bodynav\">Printer Friendly Version</a>"; ?>
That should work...or maybe
$pageid= urlencode({$_GET['pageid']});
Guys,
maybe you didn't understand the question. How can I execute PHP code from a mysql database field in a echo function?
I don't think you can, not in an echo function, as echo is a function of php, to output text and html ...
This is probably the worst way to do it, but as I can't think of any other way, I'll tell you this. 😛
I suppose you could get the code from the field and put it in a variable, then create a new 'temp.php' file with whatever that variable contains... Then when you want to use that code you could include the file.
Or you can use [man]eval[/man].