Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem ... Please HELP

Status
Not open for further replies.

alsaffar

Programmer
Oct 25, 2001
165
KW
Hi there,

I'm using a database to store my website's HTML codes.

and my table "CodeTable" consists of 3 fields (PageID, PageName, PageCode), and when I want to retrieve a page, I just select the PageName and echo the PageCode:

$Query = " SELECT PageCode FROM CodeTable WHERE PageName = '$HTTP_GET_VARS[PageName]' ";
$Result = mysql_query ($Query) or die ("Query Failed");
$PageDetails = mysql_fetch_array($Result);
echo "$PageDetails[PageCode]";

and when I want to call the desired page, just href="Pages.php?PageName=Page1"
(where Pages.php is the page that have the select statement.)

The problem is:

If the &quot;PageCode&quot; field has some PHP code embeded inside the HTML code (i.e. <html><? echo &quot;Hi&quot;; ?></html>), the PHP code will be treated as a TEXT! Although the code will be displayed in a page with PHP extension (Pages.php) but all the PHP code will be traeted as TEXT.

With HTML code, there is no problem.

Any idea how can I get the embeded PHP code get executed when I retrieve the &quot;PageCode&quot; from my table &quot;CodeTable&quot;?
 
You can't. It's either all HTML or just PHP. If you go with the just PHP idea, you have to eval your code. //Daniel
 
I used

eval('?>' . $PageDetails[PageCode]);

just before

echo &quot;$PageDetails[PageCode]&quot;;

it works fine but the PageCode get executed 2 times!!! Any idea where is the problem?
 
its solved, thanx alot guys.

$Final = eval('?>'.$PageDetails['PageCode']);
echo &quot;$Final&quot;;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top