Forum Moderators: coopster

Message Too Old, No Replies

PHP not parsing - newbie question

         

thx967

9:23 pm on Feb 24, 2005 (gmt 0)

10+ Year Member



I have a site which loads all my pages dynamically from a mysql db. The problem I am having is that the pages that have php in them don't parse. the text and graphics are there - the tables that are supposed to be generated by calling on data in the db display the php code and not the actual data. I've looked at the "eval" function but can't seem to get it to work.

any suggetions? ideas?


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Web Pages</title>
<link href="styles/styles.css" rel="stylesheet" type="text/css">
<?php
// Require the database class
require_once('includes/DbConnector.php');

// Create an object (instance) of the DbConnector
$connector = new DbConnector();

// Execute the query
$result = $connector->query('SELECT name,body FROM webpages WHERE ID = '.$HTTP_GET_VARS['id']);

// Get an array containing the resulting record
$row = $connector->fetchArray($result);

//Parse the db web page

$php_code = eval('?>' . $row['body'] . ' <?php ');

?>

</head>
<body>
<table width="800" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="352" height="20" bgcolor="003366"><img src="images/Logo.gif"></td>
<td width="448" valign="bottom" bgcolor="003366"></td>
</tr>
<tr valign="bottom">
<td height="15" colspan="2" bgcolor="003366"><div align="left">
<?php
include ('nav.php');
?>
</div></td>
</tr>
<tr>
<td colspan="2" bgcolor="#FFFFFF"><div align="left">
<br><p>
<span class="body">Web Pages </span><br>
</p>
</div></td>
</tr>
<tr valign="top">
<td height="600" colspan="2" bgcolor="#FFFFFF"><div align="left">
<span class="body">Page Name: <?php echo $row['name'];?>
<br>
<br>
</span>

//table that is populated by db

<table width="800" border="0" cellpadding="10" cellspacing="0">
<tr>
<td><div align="left" class="body"><?php print stripslashes $php_code;?>
</div></td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>

thx967

12:35 am on Feb 25, 2005 (gmt 0)

10+ Year Member



Problem Solved

I managed to get it to work by changing the following code:
<?php print stripslashes $php_code;?>

To:
<?php eval('?>' . stripslashes($row['body']) . ' <?php ');?>