PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
thx967
Forum Newbie
Posts: 20 Joined: Thu Feb 24, 2005 3:14 pm
Post
by thx967 » Thu Feb 24, 2005 3:17 pm
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ї'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>
Last edited by
thx967 on Thu Feb 24, 2005 5:02 pm, edited 1 time in total.
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098 Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia
Post
by Chris Corbyn » Thu Feb 24, 2005 3:31 pm
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?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Feb 24, 2005 3:32 pm
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.
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098 Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia
Post
by Chris Corbyn » Thu Feb 24, 2005 3:33 pm
Are you just using the .php file extension.... not a custom configured one?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Feb 24, 2005 3:35 pm
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..
Buddha443556
Forum Regular
Posts: 873 Joined: Fri Mar 19, 2004 1:51 pm
Post
by Buddha443556 » Thu Feb 24, 2005 3:40 pm
Did you use an eval() like this:
Code: Select all
eval('?>' . $the_page . '<?php ');
Note space after opening php tag.
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098 Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia
Post
by Chris Corbyn » Thu Feb 24, 2005 3:47 pm
Sorry my bad
thx967
Forum Newbie
Posts: 20 Joined: Thu Feb 24, 2005 3:14 pm
Post
by thx967 » Thu Feb 24, 2005 3:56 pm
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 ');
Buddha443556
Forum Regular
Posts: 873 Joined: Fri Mar 19, 2004 1:51 pm
Post
by Buddha443556 » Thu Feb 24, 2005 4:06 pm
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ї'body'] . ' <?php '); ?>
This eval() will act very much like using an include. If you want to capture the output use
output buffers .
thx967
Forum Newbie
Posts: 20 Joined: Thu Feb 24, 2005 3:14 pm
Post
by thx967 » Thu Feb 24, 2005 4:21 pm
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ї'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
Buddha443556
Forum Regular
Posts: 873 Joined: Fri Mar 19, 2004 1:51 pm
Post
by Buddha443556 » Thu Feb 24, 2005 4:49 pm
Yeah sure, try stripping slashes:
Code: Select all
<td><div align="left" class="body"><?php eval('?>' . stripslashes($rowї'body']) . ' <?php '); ?>
You need to make sure error isn't the $row['body'] too. What's in $row['body']?
thx967
Forum Newbie
Posts: 20 Joined: Thu Feb 24, 2005 3:14 pm
Post
by thx967 » Thu Feb 24, 2005 4:57 pm
you rock Buddha443556!!!
the strip slashes was the problem - it works now.
Thanks for your help!