Page 1 of 1

[SOLVED] PHP not parsing

Posted: Thu Feb 24, 2005 3:17 pm
by thx967
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?

Code: Select all

<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&#1111;'id']);

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

//Parse the db web page

$php_code = eval('?>' . $row&#1111;'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&#1111;'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>
:D

Posted: Thu Feb 24, 2005 3:31 pm
by Chris Corbyn
Hmmm... php isn't configured / installed on the server?? :?

What version do they claim to be running/ are you running? Have you checked out other sites on the same server that are using PHP?

Posted: Thu Feb 24, 2005 3:32 pm
by feyd
from what I remember, calling eval() is like calling a function.. if you want to store the results of the execution, you need to return data.

Posted: Thu Feb 24, 2005 3:33 pm
by Chris Corbyn
Are you just using the .php file extension.... not a custom configured one?

Posted: Thu Feb 24, 2005 3:35 pm
by feyd
he's saying the data stored in the database isn't getting parsed as php.. because it needs to be evaluated by php in order to run..

Posted: Thu Feb 24, 2005 3:40 pm
by Buddha443556
Did you use an eval() like this:

Code: Select all

eval('?>' . $the_page . '<?php ');
Note space after opening php tag.

Posted: Thu Feb 24, 2005 3:47 pm
by Chris Corbyn
Sorry my bad :oops:

Posted: Thu Feb 24, 2005 3:56 pm
by thx967
feyd wrote:from what I remember, calling eval() is like calling a function.. if you want to store the results of the execution, you need to return data.
I'm returning the data to the following line

<td><div align="left" class="body"><?php print stripslashes $php_code;?>

after it has been eval'd on this line

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

Posted: Thu Feb 24, 2005 4:06 pm
by Buddha443556
thx967 wrote:
feyd wrote:from what I remember, calling eval() is like calling a function.. if you want to store the results of the execution, you need to return data.
I'm returning the data to the following line

<td><div align="left" class="body"><?php print stripslashes $php_code;?>

after it has been eval'd on this line

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

Code: Select all

<td><div align="left" class="body"><?php eval('?>' . $row&#1111;'body'] . ' <?php '); ?>
This eval() will act very much like using an include. If you want to capture the output use output buffers.

Posted: Thu Feb 24, 2005 4:21 pm
by thx967
Buddha443556 wrote:
thx967 wrote:
feyd wrote:from what I remember, calling eval() is like calling a function.. if you want to store the results of the execution, you need to return data.
I'm returning the data to the following line

<td><div align="left" class="body"><?php print stripslashes $php_code;?>

after it has been eval'd on this line

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

Code: Select all

<td><div align="left" class="body"><?php eval('?>' . $row&#1111;'body'] . ' <?php '); ?>
This eval() will act very much like using an include. If you want to capture the output use output buffers.
I end up with the following errors using the above code. Is it due to the fact that its not stripping the slashes?

Warning: Unexpected character in input: ''' (ASCII=92) state=1 in viewPage.php(71) : eval()'d code on line 25

Parse error: parse error, unexpected $ in viewPage.php(71) : eval()'d code on line 73

Posted: Thu Feb 24, 2005 4:49 pm
by Buddha443556
Yeah sure, try stripping slashes:

Code: Select all

<td><div align="left" class="body"><?php eval('?>' . stripslashes($row&#1111;'body']) . ' <?php '); ?>
You need to make sure error isn't the $row['body'] too. What's in $row['body']?

Posted: Thu Feb 24, 2005 4:57 pm
by thx967
you rock Buddha443556!!!

the strip slashes was the problem - it works now.

Thanks for your help!